经典题目
#include"bits/stdc++.h"
using namespace std;
int diffway[1000];
int table[1000][1000];
int doctor[1000];
int dis[1000];
int vis[1000];
int ansdoctor[1000];
int main(){
memset(table, 0x3f, 4000000);
memset(dis, 0x3f, 4000);
memset(vis, 0, 4000);
memset(ansdoctor, 0, 4000);
int n, roadn, from, dest;
cin >> n >> roadn >> from >> dest;
for(int i = 0; i < n; ++i) cin >> doctor[i];
for(int i = 0; i < roadn; ++i){
int a, b, way;
cin >> a >> b >> way;
table[a][b] = table[b][a] = way;
}
dis[from] = 0;
diffway[from] = 1;
ansdoctor[from] = doctor[from];
while(1){
int p = -1;
int mindis = 0x3f3f3f3f;
for(int i = 0; i < n; ++i){
if(dis[i] < mindis && !vis[i]){
mindis = dis[i];
p = i;
}
}
if(-1 == p) break;
vis[p] = 1;
for(int i = 0; i < n; ++i){
if(0x3f3f3f3f != table[p][i] && dis[p] + table[p][i] <= dis[i]){
if(dis[p] + table[p][i] == dis[i]){
diffway[i] += diffway[p];
ansdoctor[i] = max(ansdoctor[i], ansdoctor[p] + doctor[i]);
}
else{
dis[i] = dis[p] + table[p][i];
diffway[i] = diffway[p];
ansdoctor[i] = ansdoctor[p] + doctor[i];
}
}
}
}
cout << diffway[dest] << " " << ansdoctor[dest];
}