POJ-1125-Stockbroker Grapevine
来源:互联网 发布:家用网络机顶盒哪个好 编辑:程序博客网 时间:2024/06/17 06:01
Memory Limit: 10000KTotal Submissions: 35603
Accepted: 19749
Description
Unfortunately for you, stockbrokers only trust information coming from their "Trusted sources" This means you have to take into account the structure of their contacts when starting a rumour. It takes a certain amount of time for a specific stockbroker to pass the rumour on to each of his colleagues. Your task will be to write a program that tells you which stockbroker to choose as your starting point for the rumour, as well as the time it will take for the rumour to spread throughout the stockbroker community. This duration is measured as the time needed for the last person to receive the information.
Input
Each person is numbered 1 through to the number of stockbrokers. The time taken to pass the message on will be between 1 and 10 minutes (inclusive), and the number of contacts will range between 0 and one less than the number of stockbrokers. The number of stockbrokers will range from 1 to 100. The input is terminated by a set of stockbrokers containing 0 (zero) people.
Output
It is possible that your program will receive a network of connections that excludes some persons, i.e. some people may be unreachable. If your program detects such a broken network, simply output the message "disjoint". Note that the time taken to pass the message from person A to person B is not necessarily the same as the time taken to pass it from B to A, if such transmission is possible at all.
Sample Input
32 2 4 3 52 1 2 3 62 1 2 2 253 4 4 2 8 5 31 5 84 1 6 4 10 2 7 5 202 2 5 1 50
Sample Output
3 23 10
解题思路:用floyd,题目有点水0ms,还要在加两层for循环找出最小时间和开始的人数,
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int MAXN = 105;
const int INF = 0x3f3f3f3f;
int cost[MAXN][MAXN];
int main()
{
int n;
while (scanf("%d", &n) && n) {
memset(cost, INF, sizeof(cost));
int a, b, c;
for (int i = 1; i <= n; i++) {
scanf("%d", &a);
while(a--) {
scanf("%d%d", &b, &c);
cost[i][b] = c;
}
}
for (int k = 1; k <= n; k++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
}
}
}
int time = INF;
int strat = 0;
for (int i = 1; i <= n; i++) {
int minDis = 0;
for (int j = 1; j <= n; j++) {
if (i == j) {
continue;
}
minDis = max(minDis, cost[i][j]);//我理解的他们可以同时说,所以找到最长的就是整个i到j的时间
}
if (time > minDis) {
time = minDis;
strat = i;
}
}
if (time >= INF) {
printf("disjoint\n");
}
else {
printf("%d %d\n", strat, time);
}
}
return 0;
}
- poj 1125 Stockbroker Grapevine
- POJ 1125 Stockbroker Grapevine
- POJ 1125 Stockbroker Grapevine
- poj 1125 Stockbroker Grapevine
- poj 1125 Stockbroker Grapevine
- POJ 1125 Stockbroker Grapevine
- poj 1125 Stockbroker Grapevine
- Poj 1125 Stockbroker Grapevine
- poj 1125 Stockbroker Grapevine
- POJ 1125 Stockbroker Grapevine
- poj 1125-Stockbroker Grapevine
- POJ 1125 Stockbroker Grapevine
- POJ 1125 Stockbroker Grapevine
- POJ 1125 Stockbroker Grapevine
- poj 1125 Stockbroker Grapevine
- poj 1125 Stockbroker Grapevine
- POJ 1125 Stockbroker Grapevine
- POJ 1125 Stockbroker Grapevine
- 连连跳(简单bfs)
- VOR导航原理
- POJ-1860-Currency Exchange(bellman)
- POJ-2253-Frogger
- 学习资料|王江源博客推荐,21篇优…
- POJ-1125-Stockbroker Grapevine
- POJ-1258-Agri-Net
- 卷积神经网络基础总结
- POJ-2485-Highways(kruskal)
- Globle.asax错误:异常详细信息: S…
- HDU-1166-敌兵布阵 (线段树)
- .NET 页面生命周期
- linux下使用python连接redis
- prime + heap