POJ 1125 Stockbroker Grapevine (FloydWarshall 所有点对最短路径)
2015-10-16 10:13
609 查看
#include <stdio.h> #define MAX_STOCKBROKERS 101 //10 minutes * 100 stockBrokers + 1 #define MAX_MINUTES 1001 int numOfStockBrokers; int numOfContracts; int from, to, pass; int minutes; int time[MAX_STOCKBROKERS][MAX_STOCKBROKERS]; int maxTime; int minInMax; int person; int main(){ freopen("input.txt", "r", stdin); while (scanf("%d", &numOfStockBrokers) != EOF && numOfStockBrokers != 0){ for (from = 1; from <= numOfStockBrokers; from++) for (to = from + 1; to <= numOfStockBrokers; to++) time[from][to] = time[to][from] = MAX_MINUTES; for (from = 1; from <= numOfStockBrokers; from++){ scanf("%d", &numOfContracts); while (numOfContracts--){ scanf("%d%d", &to, &minutes); time[from][to] = minutes; } } for (pass = 1; pass <= numOfStockBrokers; pass++) for (from = 1; from <= numOfStockBrokers; from++) for (to = 1; to <= numOfStockBrokers; to++) if (time[from][pass] + time[pass][to] < time[from][to]) time[from][to] = time[from][pass] + time[pass][to]; minInMax = MAX_MINUTES; for (from = 1; from <= numOfStockBrokers; from++){ maxTime = -1; for (to = 1; to <= numOfStockBrokers; to++) if (time[from][to] > maxTime) maxTime = time[from][to]; if (maxTime < minInMax){ minInMax = maxTime; person = from; } } if (minInMax == MAX_MINUTES) printf("disjoint\n"); else printf("%d %d\n", person, minInMax); } return 0; }
相关文章推荐
- 详解图的应用(最小生成树、拓扑排序、关键路径、最短路径)
- python编写的最短路径算法
- 【算法】最短路径之A*搜索
- Dijkstra和floyd——求单源点最短路径
- 初学图论-Dijkstra单源最短路径算法基于优先级队列(Priority Queue)的实现
- 初学ACM - 组合数学基础题目PKU 1833
- POJ ACM 1001
- POJ ACM 1002
- POJ 2635 The Embarrassed Cryptographe
- POJ 3292 Semi-prime H-numbers
- POJ 2773 HAPPY 2006
- POJ 3090 Visible Lattice Points
- POJ-2409-Let it Bead&&NYOJ-280-LK的项链
- POJ-1695-Magazine Delivery-dp
- POJ1523 SPF dfs
- POJ-1001 求高精度幂-大数乘法系列
- POJ-1003 Hangover
- POJ-1004 Financial Management
- 用单调栈解决最大连续矩形面积问题
- 2632 Crashing Robots的解决方法