Stockbroker Grapevine POJ 1125 Floyd
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 37069 | Accepted: 20612 |
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
3
2 2 4 3 5
2 1 2 3 6
2 1 2 2 2
5
3 4 4 2 8 5 3
1 5 8
4 1 6 4 10 2 7 5 2
0
2 2 5 1 5
0
Sample Output
3 2
3 10
Source
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
#include<string>
#include<stack>
using namespace std;
typedef long long LL;
#define MAXN 109
#define N 100
#define INF 0x3f3f3f3f
/*
所有点对其他点的最短路径中的最大值 最小的那一点!
*/
int n, k ,Min;
int g[MAXN][MAXN], maxlen[MAXN];
void Floyd()
{
for (int k = ; k <= n; k++)
{
for (int i = ; i <= n; i++)
{
for (int j = ; j <= n; j++)
{
g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
}
}
}
for (int i = ; i <= n; i++)
{
for (int j = ; j <= n; j++)
{
if (j == i) continue;
maxlen[i] = max(g[i][j], maxlen[i]);
}
if (maxlen[i] < Min)
{
Min = maxlen[i], k = i;
}
}
}
int main()
{
while (scanf("%d", &n), n)
{
memset(g, INF, sizeof(g));
memset(maxlen, -, sizeof(maxlen));
int num,t,d;
for (int i = ; i <= n; i++)
{
scanf("%d", &num);
while (num--)
scanf("%d%d", &t, &d), g[i][t] = d;
}
k = -, Min = INF;
Floyd();
if (Min != INF)
printf("%d %d\n", k, Min);
else
printf("disjoint\n");
}
}
Stockbroker Grapevine POJ 1125 Floyd的更多相关文章
- Stockbroker Grapevine - poj 1125 (Floyd算法)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 30454 Accepted: 16659 Description S ...
- poj 1125 (floyd)
http://poj.org/problem?id=1125. 题意:在经纪人的圈子里,他们各自都有自己的消息来源,并且也只相信自己的消息来源,他们之间的信息传输也需要一定的时间.现在有一个消息需要传 ...
- POJ 1125 Stockbroker Grapevine【floyd简单应用】
链接: http://poj.org/problem?id=1125 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
- 最短路(Floyd_Warshall) POJ 1125 Stockbroker Grapevine
题目传送门 /* 最短路:Floyd模板题 主要是两点最短的距离和起始位置 http://blog.csdn.net/y990041769/article/details/37955253 */ #i ...
- OpenJudge/Poj 1125 Stockbroker Grapevine
1.链接地址: http://poj.org/problem?id=1125 http://bailian.openjudge.cn/practice/1125 2.题目: Stockbroker G ...
- 【POJ 1125】Stockbroker Grapevine
id=1125">[POJ 1125]Stockbroker Grapevine 最短路 只是这题数据非常水. . 主要想大牛们试试南阳OJ同题 链接例如以下: http://acm. ...
- poj 1125 Stockbroker Grapevine(多源最短)
id=1125">链接:poj 1125 题意:输入n个经纪人,以及他们之间传播谣言所需的时间, 问从哪个人開始传播使得全部人知道所需时间最少.这个最少时间是多少 分析:由于谣言传播是 ...
- POJ 1125:Stockbroker Grapevine
Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %I64d & %I64 ...
- POJ 1125 Stockbroker Grapevine
Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 33141 Accepted: ...
随机推荐
- BFS(两点搜索) UVA 11624 Fire!
题目传送门 /* BFS:首先对火搜索,求出火蔓延到某点的时间,再对J搜索,如果走到的地方火已经烧到了就不入队,直到走出边界. */ /******************************** ...
- DataGridView 动态绑定 CheckBox
下面演示如何在 DataGridView 中动态绑定 CheckBox: public class Test { /// <summary> /// 构造器 /// </summar ...
- python批量删除文件夹
制作的python程序跑一次就占200多内存在temp下面,关键是还不释放,最开始都没有发现这个问题,知道自己的c盘越来越小才发现问题所在.所以就有了去删除temp下生成的文件 代码如下: impor ...
- [转]oracle 同义词 synonym
本文转自:http://blog.csdn.net/generalfu/article/details/7906561 同义词定义 当一个用户想访问另外一个用户的表时, 需要在表前加用户名,总加表名不 ...
- LINQ数据库技术
LINQ(Language Integrated Qyery),中文名字是语言集成查询.它提供一个统一的编程概念和语法,编程人员不需要关心将要访问的是关系数据库还是XML数据,或是远程的对象,它都采用 ...
- 关于defineProperty
var c=0; Object.defineProperty(this,'b',{ get :function(){ return ++c; } }) console.log(b===1&&a ...
- PyCharm使用指南及更改Python pip源为国内豆瓣
PyCharm基本使用 1.在PyCharm下为python项目配置python本地解释器 setting-->Project:pycharm workspace-->Project In ...
- 使用openssl搭建CA并颁发服务器证书
本来整理了一份执行脚本,但是没有找到附件功能.只好直接贴当时自己看过的链接了. 文章标题:Openssl Certificate Authority 转载链接:https://jamielinux.c ...
- GPC:使用GPC计算intersection容易出现的问题
在使用GPC计算多边形的交的时候,出现问题 //1.2. 另一种方法,判断新的多边形是否和老多边形相交 Poly cross = (PolyDefault) Clip.intersection ...
- PHP几个常用的概率算法
算法一 /** * 全概率计算 * * @param array $p array('a'=>0.5,'b'=>0.2,'c'=>0.4) * @return string 返回上面 ...