标签:des style blog http color os java io strong
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1599
Time Limit: 1000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2530 Accepted Submission(s):
1006
1 #include <iostream> 2 #include <cstdio> 3 using namespace std; 4 5 int n,node[1010][1010],map[1010][1010],Min; 6 const int INF=99999999; 7 8 int floyd() 9 { 10 for (int i=1; i<=n; i++) 11 for (int j=1; j<=n; j++) 12 { 13 node[i][j]=map[i][j]; 14 } 15 Min=INF; 16 for (int k=1; k<=n; k++) 17 { 18 for (int i=1; i<=k; i++) 19 for (int j=1; j<i; j++) 20 { 21 if (Min>node[i][j]+map[j][k]+map[k][i]) 22 Min=node[i][j]+map[j][k]+map[k][i]; 23 //cout<<Min<<endl; 24 } 25 for (int i=1; i<=n; i++) 26 for (int j=1; j<=n; j++) 27 { 28 if (node[i][j]>node[i][k]+node[k][j]) 29 node[i][j]=node[i][k]+node[k][j]; 30 } 31 } 32 return Min; 33 } 34 35 int main () 36 { 37 int m; 38 while (~scanf("%d%d",&n,&m)) 39 { 40 for (int i=1; i<=n; i++) 41 { 42 for (int j=1; j<=n; j++) 43 map[i][j]=node[i][j]=INF; 44 } 45 while (m--) 46 { 47 int a,b,c; 48 scanf("%d%d%d",&a,&b,&c); 49 if (map[a][b]>c) 50 map[a][b]=map[b][a]=c; 51 } 52 floyd(); 53 if (Min==INF) 54 printf ("It‘s impossible.\n"); 55 else 56 printf ("%d\n",Min); 57 } 58 return 0; 59 }
hdu 1599 find the mincost route (最小环与floyd算法)
标签:des style blog http color os java io strong
原文地址:http://www.cnblogs.com/qq-star/p/3942316.html