1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 5 using namespace std; 6 const int maxn = 500 + 10; 7 const int INF = 0x3f3f3f3f; 8 int pic[maxn][maxn]; //用来存图 9 int dis[maxn]; 10 int val[maxn], ans[maxn];//ans数组用来记录所走路径经过房间的权值和 11 bool vis[maxn]; 12 int n, m, sta, en; 13 14 void dij(){ 15 for (int i = 0; i<n; i++) 16 dis[i] = pic[sta][i]; 17 dis[sta] = 0; 18 ans[sta] = val[sta]; 19 for (int i = 0; i<n; i++){ 20 int min = INF; 21 int u = sta; 22 for (int j = 0; j < n; j++){ 23 if (!vis[j] && dis[j] < min){ 24 u = j; 25 min = dis[j]; 26 } 27 } 28 vis[u] = 1; 29 for (int j = 0; j<n; j++){ 30 if (dis[j]>dis[u] + pic[u][j]){ 31 dis[j] = dis[u] + pic[u][j]; 32 ans[j] = ans[u] + val[j]; 33 } 34 else if (dis[j] == dis[u] + pic[u][j]){ 35 ans[j] = max(ans[j], ans[u] + val[j]);//若路径花费相等,点权值取较大的。 36 } 37 } 38 } 39 } 40 41 int main(){ 42 ios::sync_with_stdio(false); 43 44 memset(pic, INF, sizeof(pic)); 45 memset(ans, 0, sizeof(ans)); 46 memset(vis, 0, sizeof(vis)); 47 48 cin >> n >> m >> sta >> en; 49 for (int i = 0; i<n; i++) 50 cin >> val[i]; 51 for (int i = 0; i<m; i++){ 52 int a, b, len; 53 cin >> a >> b >> len; 54 pic[a][b] = pic[b][a] = len; 55 } 56 dij(); 57 cout << dis[en] << ‘ ‘ << ans[en] << endl; 58 59 return 0; 60 }