POJ 1125 Stockbroker Grapevine Floyd 最短路
2015-05-05 13:24
423 查看
#include <cstdio> #include <iostream> #include <algorithm> #include <queue> #include <stack> #include <cstdlib> #include <cmath> #include <set> #include <map> #include <vector> #include <cstring> #define INF 100000000 using namespace std; int n; int a[105][105]; int ans[105]; int main(){ while(cin >> n,n){ for(int i = 1;i <= n;i++){ for(int j = 1;j <= n;j++){ a[i][j] = INF; } } int m; for(int i = 1;i <= n;i++){ scanf("%d",&m); for(int j = 1;j <= m;j++){ int x,v; scanf("%d%d",&x,&v); a[i][x] = v; } } for(int k = 1;k <= n;k++){ for(int i = 1;i <= n;i++){ for(int j = 1;j <= n;j++){ a[i][j] = min(a[i][j],a[i][k]+a[k][j]); } } } int max = INF; int maxn; for(int i = 1;i <= n;i++){ ans[i] = 0; for(int j = 1; j <= n;j++){ if(i != j && a[i][j] > ans[i]){ ans[i] = a[i][j]; } } if(ans[i] < max){ max = ans[i]; maxn = i; } } if(max >= INF){ cout << "disjoint" << endl; } else{ printf("%d %d\n",maxn,max); } } return 0; }
相关文章推荐
- POJ 1125 Stockbroker Grapevine(最短路 Floyd)
- POJ 1125 Stockbroker Grapevine (最短路 floyd)
- poj 1125 Stockbroker Grapevine(最短路 简单 floyd)
- POJ Stockbroker Grapevine 1125 多源最短路(Floyd)
- POJ ACM 1125 Stockbroker Grapevine (最短路Floyd)
- poj 1125 Stockbroker Grapevine (Floyd最短路)【模板】
- POJ 1125 Stockbroker Grapevine(最短路&Floyd)
- POJ 1125-Stockbroker Grapevine(最短路-含孤立点)
- poj 1125 -- Stockbroker Grapevine (最短路)
- POJ - 1125 Stockbroker Grapevine(Floyd)
- POJ 1125 Stockbroker Grapevine 最短路folyd算法
- 初级->图算法->最短路 poj 1125 Stockbroker Grapevine
- POJ-1125 Stockbroker Grapevine 最短路
- POJ 1125 Stockbroker Grapevine Floyd .
- POJ1125_Stockbroker Grapevine_最短路::弗洛伊德
- POJ 1125 Stockbroker Grapevine(最短路练习)
- POJ 1125 Stockbroker Grapevine (floyd_DP)
- 【Floyd】POJ1125-Stockbroker Grapevine
- POJ 1125 Stockbroker Grapevine (最短路径.Floyd-Warshall)
- poj 1125Stockbroker Grapevine(最短路)