标签:des style color java os io strong 文件
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 28346 Accepted Submission(s): 10272
3 3 0 1 1 0 2 3 1 2 1 0 2 3 1 0 1 1 1 2
2 -1
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #include<map> #include<string> using namespace std; const int MX=1<<30; int road[210][210],pay[210],n,s,t; struct node { int s; int t; }; int bfs() { int min1=MX; node a,b; a.s=s; a.t=0; pay[a.s]=a.t; queue<node>q; q.push(a);//cout<<aaa<<endl; while(!q.empty()) { a=q.front(); q.pop(); for(int i=0;i<n;i++) { if(road[a.s][i]!=MX) { b.s=i; b.t=a.t+road[a.s][i]; if(b.t<pay[i]) { if(b.t<min1&&b.s==t) { min1=b.t; } pay[i]=b.t; q.push(b); } } } } if(min1==MX) return -1; return min1; } int main() { int m; while(scanf("%d%d",&n,&m)!=EOF) { int i,j; for(i=0;i<210;i++) { for(j=0;j<210;j++) { road[i][j]=MX; } pay[i]=MX; } int a,b,c; for(i=0;i<m;i++) { scanf("%d%d%d",&a,&b,&c); if(road[a][b]>c) { road[a][b]=c; road[b][a]=c; } } scanf("%d%d",&s,&t); if(s==t) { printf("0\n");continue; } printf("%d\n",bfs()); } return 0; }
标签:des style color java os io strong 文件
原文地址:http://blog.csdn.net/fljssj/article/details/38553991