标签:除了 最大值 需要 数组 路径 else its 条件 城市
#include<bits/stdc++.h>
using namespace std;
const int maxn = 510;
const int INF = 100000000;
int n, G[maxn][maxn];
bool vis[maxn] = {false};
int d[maxn];//用于记录最短路径
int num[maxn];//用于记录最短路径的条数
int weight[maxn];//记录城市中可以调动的人数
int w[maxn];
void Djikstra(int s){
fill(d, d+maxn, INF);
memset(num, 0, sizeof(num));
memset(w, 0, sizeof(w));
//fill(num, num+maxn, 0);
//fill(w, w+maxn, 0);
d[s] = 0;
num[s] = 1;
w[s] = weight[s];
for(int i = 0; i < n; i++){
int u = -1, MIN = INF;
for(int j = 0; j < n; j++){
if(vis[j] == false && d[j] < MIN){
u = j;
MIN = d[j];
}
}
if(u == -1) return;
vis[u] = true;
for(int v = 0; v < n; v++){
if(vis[v] == false && G[u][v] != INF){
if(d[u] + G[u][v] < d[v]){
d[v] = d[u] + G[u][v];
w[v] = w[u] + weight[v];
num[v] = num[u];
}else if(d[u] + G[u][v] == d[v]){
num[v] += num[u];
if(w[u] + weight[v] > w[v]){
w[v] = w[u] + weight[v];
}
}
}
}
}
}
int main(){
int m, c1, c2;
scanf("%d%d%d%d", &n, &m, &c1, &c2);
for(int i = 0; i < n; i++){
scanf("%d", &weight[i]);
}
int id1, id2, L;//城市编号和他们之间的距离
fill(G[0], G[0]+maxn*maxn, INF);
for(int i = 0; i < m; i++){
scanf("%d %d %d", &id1, &id2, &L);
G[id1][id2] = L;
G[id2][id1] = L;
}
Djikstra(c1);
printf("%d %d", num[c2], w[c2]);
return 0;
}
标签:除了 最大值 需要 数组 路径 else its 条件 城市
原文地址:https://www.cnblogs.com/tsruixi/p/12384951.html