首页 > 代码库 > POJ 1125 Stockbroker Grapevine
POJ 1125 Stockbroker Grapevine
/**POJ 1125 Stockbroker Grapevine*maxdist 为从第i个人出发 传递完成所需的最大距离*ans 为maxdist 中的最小值*/#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int MAXN = 110;const int INF = 0x3f3f3f3f;int dist[MAXN][MAXN];int n;int floyd(){ int i, j, k; for (k = 0; k < n; k ++) { for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); } } }}int main(){ int i, j, num; while (~scanf("%d", &n) && n) { memset(dist, INF, sizeof(dist)); for (i = 0; i < n; i ++) { scanf("%d", &num); while (num--) { scanf("%d", &j); scanf("%d", &dist[i][j - 1]); } } floyd(); int ans = INF, maxdist, pos; for (i = 0; i < n; i++) { maxdist = -1; for (j = 0; j < n; j ++) { if (i != j && maxdist < dist[i][j]) { maxdist = dist[i][j]; } } if (ans > maxdist) { ans = maxdist; pos = i; } } if (ans == INF) { printf("disjoint\n"); } else { printf("%d %d\n", pos+1, ans); } } return 0;}
POJ 1125 Stockbroker Grapevine
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。