标签:des style color java os io strong 文件
3 3 0 1 1 0 2 3 1 2 1 0 2 3 1 0 1 1 1 2
2 -1
#include <cstdio> #define MAX 99999999 int map[220][220],n,m,s,t; int main() { int i,j,k,s1,s2,s3; while(scanf("%d%d",&n,&m)!=EOF) { for(i=0;i<n;i++) for(j=0;j<n;j++) { map[i][j]=MAX; if(i==j) map[i][i]=0; } for(i=1;i<=m;i++) { scanf("%d%d%d",&s1,&s2,&s3); if(s3<map[s2][s1]) map[s2][s1]=map[s1][s2]=s3; } scanf("%d%d",&s,&t); if(s==t) { printf("0\n");continue; } for(i=0;i<n;++i) for(j=0;j<n;++j) for(k=0;k<n;++k) if(map[j][k]>map[i][k]+map[j][i]) map[j][k]=map[i][k]+map[j][i]; if(map[s][t]==MAX) printf("-1\n"); else printf("%d\n",map[s][t]); } return 0; }
标签:des style color java os io strong 文件
原文地址:http://blog.csdn.net/hpuhjl/article/details/38517435