Title Link: Stockbroker Grapevine
Test INSTRUCTIONS: N Individual stocks, everyone can give a messenger to others, line 1th N, line x first is the x-1 person can give a messenger to several people, followed by who can give a messenger and the time of the Messenger, ask from the first few people to use the least time to start a messenger
Water problem, Floyd once;
ME 676KB
TI 16MS
#include <iostream> #include <stdio.h> #include <stdlib.h> #include <math.h> #include < string.h> #include <algorithm>const int INF = 1e7;const int N = 105;using namespace Std;int mapp[n][n],n;void Init () {for (int i = 1;i<=n;i++) {for (int j = 1;j<=n;j++) {Mapp[i][j] = INF; }}}void Floyd () {int k,j,i; for (k = 1;k<=n;k++) {for (i = 1;i<=n;i++) {for (j=1;j<=n;j++) { if (Mapp[i][j] > Mapp[i][k] + mapp[k][j]) mapp[i][j] = Mapp[k][j] + mapp[i][k]; }}}}int Main () {int s,wz,ti; while (scanf ("%d", &n), n) {init (); for (int i = 1;i<=n;i++) {scanf ("%d", &s); for (int j = 1;j<=s;j++) {scanf ("%d%d", &wz,&ti); MAPP[I][WZ] = ti; }} Floyd (); int st = -1,maxx= 0,ti = INF; for (int i = 1;i<=n;i++) {maxx = 0; for (int j = 1;j<=n;j++) {if (i==j) continue; if (Mapp[i][j]> maxx) {maxx = Mapp[i][j]; }} if (Ti>maxx) {ti = Maxx; st = i; }} if (St!=-1) printf ("%d%d\n", st,ti); Else puts ("disjoint"); } return 0;}
POJ 1125-stockbroker Grapevine