1125 pojBig Christmas Tree
来源:互联网 发布:经传软件跟风统计 编辑:程序博客网 时间:2024/06/05 00:56
本体我只想说说题意: 在给出的所有点中找到一个点,到所有点的时间最短,输出这个点,并输出最短距离,如果不连通, 则输出“disjoint” 由于题意没看明白, 错了好多次。
#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int M = 105;const int inf = 99999999;int dist[M][M];int n;void init(){ for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) dist[i][j] = inf;}void floyd(){ int s; int maxlenght = 0; int maxn = inf; for(int k = 1; k <= n; k++) for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) if(i != j && dist[i][j] > dist[i][k] + dist[k][j]) dist[i][j] = dist[i][k] + dist[k][j]; for(int i = 1; i <= n; i++){ maxlenght = 0; for(int j= 1; j <= n; j++) if(i != j && maxlenght < dist[i][j]) maxlenght = dist[i][j]; if(maxn > maxlenght){ maxn = maxlenght; s = i; } } if(maxn != inf) printf("%d %d\n", s, maxn); else printf("disjoint\n");}int main(){ int m , a, b; while(scanf("%d", &n) != EOF){ if(!n) break; init(); for(int i = 1; i <= n; i++){ scanf("%d", &m); for(int j = 0; j < m; j++){ scanf("%d%d", &a, &b); dist[i][a] = b; } } floyd(); } return 0;}
0 0
- 1125 pojBig Christmas Tree
- POJ3013:Big Christmas Tree
- POJ_3013_Big Christmas Tree
- POJ3013 Big Christmas Tree
- Big Christmas Tree
- pku3013 Big Christmas Tree
- Big Christmas Tree POJ
- Poj 3013 Big Christmas Tree
- poj 3013 big christmas tree
- POJ - 3013 Big Christmas Tree
- POJ_3013_Big Christmas Tree(最短路)
- POJ 3013 Big Christmas Tree
- POJ3013 Big Christmas Tree(SPFA)
- POJ 3013 Big Christmas Tree
- POJ 3013:Big Christmas Tree
- POJ 3013 Big Christmas Tree
- poj3013 Big Christmas Tree dijkstra
- POJ--3013[Big Christmas Tree] (SPFA)
- Ansi C 函数库
- 13年微软
- 杭电1016 Prime Ring Problem(DFS)
- android 中bundle对象
- boost posix_time 获取当前时间
- 1125 pojBig Christmas Tree
- 14年迅雷
- Linux线程属性总结
- 大小端
- 敌兵布阵
- 网络知识基础必备
- 以前写的一个面向对象的贪吃蛇游戏
- 【阅读】《Head First Javascript》第五章——循环
- 最大子数列和的问题