标签:
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 37203 Accepted Submission(s):
16182
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int dis[105][105]; int n,m; #define INF 0x3f3f3f3f void floyed() { for(int k=1;k<=n;k++) { for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { if(dis[i][k]<INF&&dis[k][j]<INF) dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]); } } } } int main() { while(scanf("%d%d",&n,&m)!=EOF&&n&&m) { int a,b,c; //memset(dis,INF,sizeof(dis)); for(int i=1;i<=n;i++) { dis[i][i]=INF; for(int j=i+1;j<=n;j++) dis[i][j]=dis[j][i]=INF; } for(int i=1;i<=m;i++) { scanf("%d%d%d",&a,&b,&c); dis[a][b]=dis[b][a]=c; } floyed(); printf("%d\n",dis[1][n]); } }
标签:
原文地址:http://www.cnblogs.com/qianyanwanyu--/p/4393701.html