标签:des style color java os io strong 数据
Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 14761 Accepted Submission(s): 3479
6 xiasha westlake xiasha station 60 xiasha ShoppingCenterofHangZhou 30 station westlake 20 ShoppingCenterofHangZhou supermarket 10 xiasha supermarket 50 supermarket westlake 10 -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[160][160],pay[160],aaa; struct node { int s; int t; }; int bfs() { int min1=MX; node a,b; a.s=1; 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=2;i<=aaa;i++) { if(road[a.s][i]!=MX) { b.s=i; b.t=a.t+road[a.s][i]; if(b.t<pay[i]) { //cout<<a.s<<" *** "<<i<<endl; if(b.t<min1&&b.s==2) { min1=b.t; } pay[i]=b.t; q.push(b); } } } } //cout<<min1<<endl; if(min1==MX) return -1; return min1; } int main() { int n; while(scanf("%d",&n)!=EOF) { if(n==-1)break; map<string,int>zm; char a[40],b[40],c[40],d[40]; scanf("%s%s",c,d); zm[c]=1; zm[d]=2; aaa=3; int i,j,q; for(i=1;i<160;i++) { for(j=1;j<160;j++) { road[i][j]=MX; } pay[i]=MX; } for(i=0;i<n;i++) { scanf("%s%s%d",a,b,&q); if(zm[a]==0) zm[a]=aaa++; if(zm[b]==0) zm[b]=aaa++; if(road[zm[a]][zm[b]]>q) { road[zm[a]][zm[b]]=q; road[zm[b]][zm[a]]=q; } } /*for(i=1;i<aaa;i++) { for(j=1;j<aaa;j++) { if(road[i][j]==MX) printf("0"); else printf("%d",road[i][j]/10); } printf("\n"); }*/ if(strcmp(c,d)==0) { printf("0\n");continue; } printf("%d\n",bfs()); } return 0; }
50 Hint: The best route is: xiasha->ShoppingCenterofHangZhou->supermarket->westlake 虽然偶尔会迷路,但是因为有了你的帮助 **和**从此还是过上了幸福的生活。 ――全剧终――
HDU2112HDU Today,布布扣,bubuko.com
标签:des style color java os io strong 数据
原文地址:http://blog.csdn.net/fljssj/article/details/38553829