当前位置:网站首页>1003 emergency (25 points), "DIJ deformation"
1003 emergency (25 points), "DIJ deformation"
2022-07-06 02:54:00 【Yang tree Yang tree】
#include <cstring>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#define dd double
#define PII pair<int,int>
#define int long long
using namespace std;
const dd eps = 1e-6;
const int mod = 1000003;
const int N = 1e3+10;
int n,m;
int c1,c2;
int cnt[N],sum[N];
int weight[N];
// cnt[j] Deposit is j The number of shortest circuits to the starting point .
// sum[j] Deposit is j The largest number of people on the shortest path to the starting point
/*
n - Number of cities
m - The number of roads
c1 and c2 Cities that must be rescued
*/
//#define int long long
const int INF = 0x3f3f3f3f3f3f3f3f;
int g[N][N], dist[N]; // Dense graphs are stored in adjacency matrices
bool st[N];
void dijkstra()
{
// The starting point is initialized to 0, Other points are initialized to infinity (INF)
memset(dist, 0x3f, sizeof dist);
dist[c1] = 0;
// The starting quantity is 1
cnt[c1]=1;
// Starting number is w1
sum[c1]=weight[c1];
for(int i = 1; i <= n; i++)
{
// Find the point in which the shortest circuit is not currently determined The shortest distance
int t = -1;
for(int j = 0; j < n; j++)
if(!st[j] && (t == -1 || dist[t] > dist[j])) t = j;
// use t Update other points
for(int j = 0; j < n; j++)
{
if(dist[j]>dist[t]+g[t][j])
{
dist[j]=dist[t]+g[t][j];
cnt[j]=cnt[t];
sum[j]=sum[t]+weight[j];
}
else if(dist[j]==dist[t]+g[t][j])
{
cnt[j]+=cnt[t];
sum[j]=max(sum[j],sum[t]+weight[j]);
}
}
// t The shortest circuit has been determined
st[t] = true;
}
// if INF It means there is no way
}
signed main()
{
// Input part
memset(g,0x3f,sizeof(g));
cin>>n>>m>>c1>>c2;
for(int i=0;i<n;i++)
{
cin>>weight[i];
}
for(int i=0;i<m;i++)
{
int a,b,c;
cin>>a>>b>>c;
g[a][b]=g[b][a]=min(g[a][b],c);
}
dijkstra();
cout<<cnt[c2]<<" "<<sum[c2]<<endl;
return 0;
//
}
边栏推荐
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 16
- Reverse repackaging of wechat applet
- MySQL winter vacation self-study 2022 11 (5)
- MySQL advanced notes
- Add one to non negative integers in the array
- Pat 1084 broken keyboard (20 points) string find
- 07 singleton mode
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 15
- MySQL winter vacation self-study 2022 11 (9)
- Modeling specifications: naming conventions
猜你喜欢
Referenceerror: primordials is not defined error resolution
Linear programming matlab
[pointer training - eight questions]
Solve 9 with C language × 9 Sudoku (personal test available) (thinking analysis)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 7
Gifcam v7.0 minimalist GIF animation recording tool Chinese single file version
Déduisez la question d'aujourd'hui - 729. Mon emploi du temps I
[matlab] access of variables and files
Li Kou today's question -729 My schedule I
Huawei, H3C, Cisco command comparison, mind map form from the basic, switching, routing three directions [transferred from wechat official account network technology alliance station]
随机推荐
2.13 simulation summary
tcpdump: no suitable device found
Redis skip table
JS regular filtering and adding image prefixes in rich text
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 17
"Hands on learning in depth" Chapter 2 - preparatory knowledge_ 2.5 automatic differentiation_ Learning thinking and exercise answers
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 11
Classic interview question [gem pirate]
OCR文字识别方法综述
MySQL advanced notes
Gifcam v7.0 minimalist GIF animation recording tool Chinese single file version
PMP practice once a day | don't get lost in the exam -7.5
技术分享 | undo 太大了怎么办
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 6
Six stone management: why should leaders ignore product quality
【若依(ruoyi)】设置主题样式
【若依(ruoyi)】ztree 自定义图标(iconSkin 属性)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 18
Technology sharing | what if Undo is too big
【若依(ruoyi)】启用迷你导航栏