poj1125floyd
来源:互联网 发布:mac win7 0x80070570 编辑:程序博客网 时间:2024/06/06 02:30
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 2
3 10
这道题虽然是道水题,floyd入门题,费了我不少神,无语~~~~
用floyd求出每两点的最短路,然后求出每点到其他点最大的,再比出最小的
说实在的,我还是不太明白题目要求的到底是什么
崩溃~~~
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#define inf 1000000000
using namespace std;
int n;
int d[110][110];
int ans,ansi;
void init()
{
memset(d, -1, sizeof(d));
for (int i = 0; i < n; i++)
{
int m;
scanf("%d", &m);
for (int j = 0; j < m; j++)
{
int a, b;
scanf("%d%d", &a, &b);
a--;
d[i][a] = b;
}
}
}
void floyd()
{
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (d[j][i] != -1)
for (int k = 0; k < n; k++)
if (d[i][k] != -1)
if (d[j][k] == -1 || d[j][k] > d[j][i] + d[i][k])
d[j][k] = d[j][i] + d[i][k];
}
int main()
{
int m;
int maxdist;
while(scanf("%d",&n)!=EOF)
{
if(n==0)
break;
init();
floyd();
ans = 1000000000, ansi = -1;
for (int i = 0; i < n; i++)
{
bool ok = true;
int maxdist = 0;
for (int j = 0; j < n; j++)
{
if (i == j)
continue;
if (d[i][j] == -1)
{
ok = false;
break;
}
if (maxdist < d[i][j])
maxdist = d[i][j];
}
if (maxdist < ans && ok)
{
ans = maxdist;
ansi = i;
}
}
if (ansi == -1)
printf("disjoint\n");
else
printf("%d %d\n", ansi + 1, ans);
}
}
- poj1125floyd
- poj1125floyd
- POJ1125Floyd-warshall算法模板题
- Eclipse的使用秘籍,MyEclipse一样管用
- php做的主页验证码
- 鸡窝里的鹰
- mave2入门
- static_cast、dynamic_cast reinterpret_cast和const_
- poj1125floyd
- JSP 下载文件
- http://qgjie456.blog.163.com/blog/static/3545136720112305582651/
- linux 打开端口
- Asp.net 构建可扩展的的Comet Web 应用(一)
- (0)SSL/TLS/WTLS原理
- 浅谈装修模式decorator
- 目前可用的通用DNS
- C++回调函数应用