您的位置:首页 > 其它

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;
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息