6 xiasha westlake xiasha station 60 xiasha ShoppingCenterofHangZhou 30 station westlake 20 ShoppingCenterofHangZhou supermarket 10 xiasha supermarket 50 supermarket westlake 10 -1
50
Hint:
The best route is:
xiasha->ShoppingCenterofHangZhou->supermarket->westlake
虽然偶尔会迷路,但是因为有了你的帮助
**和**从此还是过上了幸福的生活。
――全剧终――
//hdu today #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<map> #define INF 0x3f3f3f3f using namespace std; char s1[35],s2[35]; int path[160][160]; int n,t,cnt; void floyd() { for(int k=1;k<cnt;k++) for(int i=1;i<cnt;i++) for(int j=1;j<cnt;j++) { if(path[i][j]>path[i][k]+path[k][j]) path[i][j]=path[i][k]+path[k][j]; } } int main() { while(scanf("%d",&n)&&n!=-1) { int flag=0; memset(path,INF,sizeof(path)); scanf("%s%s",s1,s2); if(!strcmp(s1,s2)) flag=1; map<string,int>mat; mat[s1]=1; mat[s2]=2; cnt=3; while(n--) { scanf("%s%s%d",s1,s2,&t); if(!mat[s1]) mat[s1]=cnt++; if(!mat[s2]) mat[s2]=cnt++; if(t<path[mat[s1]][mat[s2]]) path[mat[s1]][mat[s2]]=path[mat[s2]][mat[s1]]=t; } if(flag) { printf("0\n"); continue; } floyd(); if(path[1][2]==INF) printf("-1\n"); else printf("%d\n",path[1][2]); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/zhenzheni/article/details/47839871