标签:acm
点击打开链接题目链接
2 1 1 2 3 3 3 1 2 5 2 3 5 3 1 2 0 0
3 2
#include<cstdio> #include<cstring> #define MAXN 0x3f3f3f3f int minn(int a,int b) { return a>b?b:a; } int dis[105][105]; int main() { int n,m; int i,j,k; int a,b,c; while(scanf("%d %d",&n,&m)!=EOF&&(n||m)) { for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { if(i!=j) dis[i][j]=MAXN; else dis[i][j]=0; } } while(m--) { scanf("%d %d %d",&a,&b,&c); dis[a][b]=dis[b][a]=c; } for(k=1;k<=n;k++) { for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { dis[i][j]=minn(dis[i][j],dis[i][k]+dis[j][k]); } } } printf("%d\n",dis[1][n]); } return 0; }
标签:acm
原文地址:http://blog.csdn.net/qq_16843991/article/details/38867045