HDU TodayCrawling in process... Crawling failed Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
Input
Output
Sample Input
6 xiasha westlake xiasha station 60 xiasha ShoppingCenterofHangZhou 30 station westlake 20 ShoppingCenterofHangZhou supermarket 10 xiasha supermarket 50 supermarket westlake 10 -1
Sample Output
50 Hint: The best route is: xiasha->ShoppingCenterofHangZhou->supermarket->westlake 虽然偶尔会迷路,但是因为有了你的帮助 **和**从此还是过上了幸福的生活。 ��全剧终��
# include <stdio.h> # include <stdlib.h> # include <string.h> int map[160][160]; int pra[160]; int visit[160]; int dis[160]; const int inf=1<<20; int n,m; int dijstra(int start) { int min,rec; for(int i=1;i<=m;i++) { pra[i]=0; dis[i]=inf; visit[i]=0; } dis[start]=0; for(int i=1;i<=m;i++) { min=inf; for(int j=1;j<=m;j++) { if(!visit[j]&&min>dis[j]) { min=dis[j]; rec=j; } } visit[rec]=1; if(rec==2)break; for(int j=1;j<=m;j++) { if(!visit[j]&&dis[j]>map[rec][j]+dis[rec]) { dis[j]=map[rec][j]+dis[rec]; pra[j]=rec; } } } return min; } int main() { while(scanf("%d",&n)!=EOF&&n!=-1) { char str1[40],str2[40]; char str[160][40]; int val,num1,num2; int i,j,t; m=3; memset(map,0x7f,sizeof(map)); scanf("%s%s",&str[1],&str[2]); for(i=1;i<=n;i++) { scanf("%s%s%d",&str1,&str2,&val); for(j=1;j<=m;j++) { if(strcmp(str1,str[j])==0) { num1=j; break; } } if(j>m) { strcpy(str[m++],str1); num1=m-1; } for(j=1;j<=m;j++) { if(strcmp(str2,str[j])==0) { num2=j; break; } } if(j>m) { strcpy(str[m++],str2); num2=m-1; } if(map[num1][num2]>val) map[num1][num2]=map[num2][num1]=val; } t=dijstra(1); if(strcmp(str[1],str[2])==0) printf("0\n"); else { if(t==inf) printf("-1\n"); else printf("%d\n",t); } } }
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。