If there are 3 points 1 to 2 to 5 minutes 1 to 3 to 3 minutes then 5 minutes of time can be spread throughout the map so we have to find a point to other points of the longest time and the longest time to find the minimum value
Sample Input
3//Node count
2 2 4 3 5//point 1 connected to another 2 points 1->2 weight is 4 1->3 weight value 5
2 1 2 3 6//point 2 with ...
2 1 2 2 2//point 3 ...
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
Sample Output
3 2
3 10
1# include <iostream>2# include <cstdio>3# include <cstring>4# include <string>5# include <algorithm>6# include <cmath>7# include <map>8# define LLLong Long9 using namespacestd;Ten One Const intMAXN = the ; A Const intINF =0x3f3f3f3f; - intDIS[MAXN][MAXN]; - intN; the - voidFloyed ()//node from 1~n number - { - inti,j,k; + for(k=1; k<=n;k++) - for(i=1; i<=n;i++) + for(j=1; j<=n;j++) A if(Dis[i][k]+dis[k][j] <Dis[i][j]) atdis[i][j]=dis[i][k]+Dis[k][j]; - - } - - intMain () - { in //freopen ("In.txt", "R", stdin); - while(SCANF ("%d", &N), N) to { + intI, J; - for(i=1; i<=n;i++) the for(j=1; j<=n;j++) * { $ if(I==J) dis[i][j]=0;Panax Notoginseng Elsedis[i][j]=INF; - } the intm, V, W; + for(i=1; i<=n;i++) A { thescanf"%d", &m); + while(m--) - { $scanf"%d%d", &v, &W); $ if(W <Dis[i][v]) -DIS[I][V] =W; - } the } - floyed ();Wuyi intAns =INF; the intK; - for(i=1; i<=n;i++) Wu { - intt =0 ; About for(j=1; j<=n;j++) $ { - if(I! = J && Dis[i][j] >t) - { -t =Dis[i][j]; A } + } the if(T <ans) - { $Ans =T; theK =i; the } the } the if(ans! =INF) -printf"%d%d\n", k, ans); in Else theprintf"disjoint\n") ; the } About return 0; the}
View Code
POJ 1125 Rumors spread Floyd template problem