Description
Input
Output
Sample Input
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
Sample Output
3 2 3 10
题意:It takes a certain amount of time for a specific stockbroker to pass the rumour on to each of his colleagues.(这句话是重点·)
让你找一个人做为传播流言的源点,这个人传播给其他所有人的时间要是最短的,那么只需要先找到每个人传播给其他人其中所用时间最长的(同时进行传播,即只需要找到传播的最慢的那个时间),当每个人都当过源点遍历完后比较哪个人传播给其他人最快
#include<stdio.h> #define INF 0x3f3f3f3f #define N 110 #define min(a, b) (a < b ? a : b) int G[N][N], n; void Init() { int i, j; for (i = 0; i <= n; i++) { for (j = 0; j <= n; j++) { if (i == j) G[i][j] = 0; else G[i][j] = INF; } } } void Dist() { int i, j, k; for (k = 1; k <= n; k++) { for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) G[i][j] = min(G[i][j], G[i][k]+G[k][j]); } } } int main () { int m, a, b, i, j, ans, idex, Min; while (scanf("%d", &n), n) { Init(); for (i = 1; i <= n; i++) { scanf("%d", &m); while (m--) { scanf("%d %d", &a, &b); G[i][a] = b; } } Dist(); ans = INF; for (i = 1; i <= n; i++) { Min = 0; for (j = 1; j <= n; j++) { if (G[i][j] > Min) Min = G[i][j]; } if (Min < ans) { ans = Min; idex = i; } } if (ans == INF) printf("disjoint\n"); else printf("%d %d\n", idex, ans); } return 0; }
POJ 1125 Stockbroker Grapevine
原文:http://www.cnblogs.com/syhandll/p/4676313.html