Stockbroker Grapevine
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 37069   Accepted: 20612

Description

Stockbrokers are known to overreact to rumours. You have been contracted to develop a method of spreading disinformation amongst the stockbrokers to give your employer the tactical edge in the stock market. For maximum effect, you have to spread the rumours in the fastest possible way.

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

Your program will input data for different sets of stockbrokers. Each set starts with a line with the number of stockbrokers. Following this is a line for each stockbroker which contains the number of people who they have contact with, who these people are, and the time taken for them to pass the message to each person. The format of each stockbroker line is as follows: The line starts with the number of contacts (n), followed by n pairs of integers, one pair for each contact. Each pair lists first a number referring to the contact (e.g. a '1' means person number one in the set), followed by the time in minutes taken to pass a message to that person. There are no special punctuation symbols or spacing rules.

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

For each set of data, your program must output a single line containing the person who results in the fastest message transmission, and how long before the last person will receive any given message after you give it to this person, measured in integer minutes. 
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

Southern African 2001

Stockbroker Grapevine
#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的更多相关文章

  1. Stockbroker Grapevine - poj 1125 (Floyd算法)

      Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 30454   Accepted: 16659 Description S ...

  2. poj 1125 (floyd)

    http://poj.org/problem?id=1125. 题意:在经纪人的圈子里,他们各自都有自己的消息来源,并且也只相信自己的消息来源,他们之间的信息传输也需要一定的时间.现在有一个消息需要传 ...

  3. POJ 1125 Stockbroker Grapevine【floyd简单应用】

    链接: http://poj.org/problem?id=1125 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...

  4. 最短路(Floyd_Warshall) POJ 1125 Stockbroker Grapevine

    题目传送门 /* 最短路:Floyd模板题 主要是两点最短的距离和起始位置 http://blog.csdn.net/y990041769/article/details/37955253 */ #i ...

  5. OpenJudge/Poj 1125 Stockbroker Grapevine

    1.链接地址: http://poj.org/problem?id=1125 http://bailian.openjudge.cn/practice/1125 2.题目: Stockbroker G ...

  6. 【POJ 1125】Stockbroker Grapevine

    id=1125">[POJ 1125]Stockbroker Grapevine 最短路 只是这题数据非常水. . 主要想大牛们试试南阳OJ同题 链接例如以下: http://acm. ...

  7. poj 1125 Stockbroker Grapevine(多源最短)

    id=1125">链接:poj 1125 题意:输入n个经纪人,以及他们之间传播谣言所需的时间, 问从哪个人開始传播使得全部人知道所需时间最少.这个最少时间是多少 分析:由于谣言传播是 ...

  8. POJ 1125:Stockbroker Grapevine

    Stockbroker Grapevine Time Limit: 1000MS   Memory Limit: 10000KB   64bit IO Format: %I64d & %I64 ...

  9. POJ 1125 Stockbroker Grapevine

    Stockbroker Grapevine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 33141   Accepted: ...

随机推荐

  1. python自动化测试学习笔记-9python的日志模块

    参考 logging模块,用来处理python中的日志: import logging logging.debug('debug')logging.info('info')logging.warnin ...

  2. python自动化测试学习笔记-unittest参数化

    做接口测试的时候,当一个参数需要输入多个值的时候,就可以使用参数来实现: python中unittest单元测试,可以使用nose_parameterized来实现: 首先需要安装:pip  inst ...

  3. ASP.NET XML文件

    XML是一种标记语言,具有描述所有已知和未知数据的能力.XML扩展性比较好,可以为新的数据类型制定新的数据描述规则,作为对标记集的扩展. XML的特点: 1.XML数据可以跨平台使用并可以被人阅读理解 ...

  4. Modbus通讯协议简介

    Modbus协议简介 Modbus协议最初由Modicon公司开发出来,此协议支持传统的RS-232.RS-422.RS-485和以太网设备,许多工业设备,包括PLC,DCS,智能仪表等都在使用Mod ...

  5. Python操作远程数据库

    我的项目要往数据库中插入create_time和update_time,那就势必要引用现在的系统时间,经过大量的查找,终于发现往python是没有对应时间datetime的相关通配符的,那么我们要怎么 ...

  6. axios 正确打开方式

    一.安装1. 利用npm安装npm install axios --save2. 利用bower安装bower install axios --save3. 直接利用cdn引入<script s ...

  7. javascript按钮点击事件问题

    今天弄了个小测试,结果发现了点问题. 就是有一个按钮的点击事件,页面加载时候没反应,只有F12启用开发人员工具的时候才有反应.后来反复测试发现名字起的不太合理 function onclick(){ ...

  8. java内存组成

     java内存组成介绍:堆(Heap)和非堆(Non-heap)内存 按照官方的说法:“Java 虚拟机具有一个堆,堆是运行时数据区域,所有类实例和数组的内存均从此处分配.堆是在 Java 虚拟机启动 ...

  9. js获取微信版本号的方法

    微信现在几乎已经普遍在使用,但是微信版本一直在更新,不同的版本有不同的功能,于是了解微信的版本号很重要,以便自己及时更新体验新的功能.那么如何用js获取微信版本号呢? 一.判断微信版本号 ? 1 2 ...

  10. 判断点击第几个按钮JS代码的三种方法

    方法一:使用下标实现<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> < ...