标签:
2 1 1 2 3 3 3 1 2 5 2 3 5 3 1 2 0 0
3 2
#include <stdio.h> #include <string.h> #include <algorithm> #define inf 0x3f3f3f3f using namespace std; const int N =1005; int map[N][N]; int m,n; int main(){ int i,j,k; while(~scanf("%d %d",&n,&m)){ if(n==0&&m==0) break; memset(map,inf,sizeof(map)); for(i=1;i<=m;i++){ int x,y,z; scanf("%d %d %d",&x,&y,&z); map[x][y]=min(map[x][y],z); map[y][x]=min(map[y][x],z); } for(k=1;k<=n;k++) for(i=1;i<=n;i++) for(j=1;j<=n;j++) if(map[i][j]>map[i][k]+map[j][k]) map[i][j]=map[i][k]+map[k][j]; printf("%d\n",map[1][n]); } return 0; }
标签:
原文地址:http://blog.csdn.net/qq_27717967/article/details/51348052