标签:sub isp none ring accept cst mem ref http
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 96778 Accepted Submission(s): 41849
借鉴链接:https://blog.csdn.net/UncleJokerly/article/details/79703622
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> using namespace std; const int INF = 0x3f3f3f3f; const int maxn = 100 + 10; int mp[maxn][maxn],dis[maxn],book[maxn],node,edge; void dijkstra(){ for(int i = 1; i <= node; i++) dis[i] = mp[1][i]; for(int i = 1; i <= node - 1; i++){ int minn = INF,u; for(int j = 1; j <= node; j++){ if(book[j] == 0 && dis[j] < minn){ minn = dis[j]; u = j; } } book[u] = 1; for(int j = 1; j <= node; j++){ if(book[j] == 0 && dis[u] + mp[u][j] < dis[j]){ dis[j] = dis[u] + mp[u][j]; } } } printf("%d\n",dis[node]); } int main(){ while(~scanf("%d%d",&node,&edge) && node && edge){ for(int i = 1; i <= node; i++){ for(int j = 1; j <= node; j++){ if(i==j) mp[i][j] = 0; else mp[i][j] = INF; } } int m,n,t; for(int i = 1; i <= edge; i++){ scanf("%d%d%d",&m,&n,&t); if(t < mp[m][n]) mp[m][n] = mp[n][m] = t; } dijkstra(); } return 0; }
标签:sub isp none ring accept cst mem ref http
原文地址:https://www.cnblogs.com/Weixu-Liu/p/10416689.html