标签:des style blog http java color
3 2 2 4 3 5 2 1 2 3 6 2 1 2 2 2 5 3 4 4 2 8 5 3 1 5 8 4 1 6 4 10 2 7 5 2 0 2 2 5 1 5 0
3 2 3 10
解题:Floy算法,选择一个人,从这个人传递信息到其他的人的最长时间最短。
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #define LL long long 13 #define INF 0x3f3f3f 14 using namespace std; 15 int mp[101][101]; 16 int main() { 17 int n,i,j,u,v,w,k; 18 while(scanf("%d",&n),n) { 19 for(i = 1; i <= n; i++) 20 for(j = 1; j <= n; j++) 21 mp[i][j] = INF; 22 for(i = 1; i <= n; i++) { 23 scanf("%d",&j); 24 while(j--) { 25 scanf("%d%d",&v,&w); 26 mp[i][v] = w; 27 } 28 } 29 for(k = 1; k <= n; k++) { 30 for(i = 1; i <= n; i++) { 31 for(j = 1; j <= n; j++) 32 if(mp[i][k] < INF && mp[k][j] < INF && mp[i][j] > mp[i][k]+mp[k][j]) 33 mp[i][j] = mp[i][k]+mp[k][j]; 34 } 35 } 36 int ans = INF,index,temp; 37 for(i = 1; i <= n; i++) { 38 temp = 0; 39 for(j = 1; j <= n; j++) { 40 if(i == j) continue; 41 if(mp[i][j] > temp) temp = mp[i][j]; 42 } 43 if(temp < ans) { 44 ans = temp; 45 index = i; 46 } 47 } 48 printf("%d %d\n",index,ans); 49 } 50 return 0; 51 }
图论trainning-part-1 G. Stockbroker Grapevine,布布扣,bubuko.com
图论trainning-part-1 G. Stockbroker Grapevine
标签:des style blog http java color
原文地址:http://www.cnblogs.com/crackpotisback/p/3860145.html