标签:imu distance size ++ 描述 esc tput details back
题目连接:
http://poj.org/problem?id=2387
Description
Input
Output
Sample Input
5 5 1 2 20 2 3 30 3 4 20 4 5 20 1 5 100
Sample Output
90
Hint
1 #include<stdio.h> 2 #include<string.h> 3 int e[1010][1010],dis[1010],bk[1010]; 4 int main() 5 { 6 int i,j,min,t,t1,t2,t3,n,u,v; 7 int inf=99999999; 8 while(scanf("%d%d",&t,&n)!=EOF) 9 { 10 for(i=1;i<=n;i++) 11 { 12 for(j=1;j<=n;j++) 13 { 14 if(i==j) 15 e[i][j]=0; 16 else 17 e[i][j]=inf; 18 } 19 } 20 for(i=1;i<=t;i++) 21 { 22 scanf("%d%d%d",&t1,&t2,&t3); 23 if(e[t1][t2]>t3) 24 { 25 e[t1][t2]=t3; 26 e[t2][t1]=t3; 27 } 28 } 29 for(i=1;i<=n;i++) 30 dis[i]=e[1][i]; 31 memset(bk,0,sizeof(bk)); 32 bk[1]=1; 33 for(i=1;i<=n-1;i++) 34 { 35 min=inf; 36 for(j=1;j<=n;j++) 37 { 38 if(bk[j]==0&&dis[j]<min) 39 { 40 min=dis[j]; 41 u=j; 42 } 43 } 44 bk[u]=1; 45 for(v=1;v<=n;v++) 46 { 47 if(e[u][v]<inf && dis[v]>dis[u]+e[u][v]) 48 dis[v]=dis[u]+e[u][v]; 49 } 50 } 51 printf("%d\n",dis[n]); 52 } 53 return 0; 54 }
POJ 2387 Til the Cows Come Home
标签:imu distance size ++ 描述 esc tput details back
原文地址:http://www.cnblogs.com/wenzhixin/p/7387613.html