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

描述:众所周知,证券业依靠的是过度的传言。你需要想出让股票经纪人传播假消息让雇主在股票市场上的占据优势的方法。为了获得最大的效果,你必须以最快的方式传播谣言。对于你来说不幸的是,股票经纪人只信任来自他们的“可信任的来源”的信息,这意味着你要考虑到他们的接触结构时的谣言。这需要一个特定的经纪人和一定的时间吧谣言传递到每个同事。你的任务是编写一个程序,告诉你选择哪一个股票经纪人为谣言的出发点,以及花费多少时间,谣言才可以传遍了整个股票经纪人社区。这个时间是根据最后一个人得到的信息的时间所衡量的。
 
输入:你的程序将包含多组股票经纪人的输入数据。每组始于一个股票经纪人的数量。每行的几组数字第一个表示股票经纪人所接触的人以及把消息传递给这个人所花费的时间。每个股票经纪人的格式如下:每行的开始n表示有几对整数,一对为一个传播人。每一对上的第一个数字指的传播人(例如,一个' 1 '的意思是人在该组中的一个),然后是花费几分钟把消息传递给那个人。没有特殊标点符号或间隔规则。

输出:对于每一组数据,你的程序必须输出一行包含的最快的消息传输人结果,以及最后一个人收到消息所花费的所有时间,分钟以整数计时。你的程序可能会收到的一些关系会排除一些人,也就是有些人可能无法访问。如果你的程序检测到这样一个破碎的网络,只需输出消息“disjoint”。请注意,所花费的时间是从A传递消息到B,B传递信息到A不一定是花费同样的传递时间,但此类传播也是可能的。

 
 #include <iostream>
#include <cstdio>
#include <stack>
#include <queue>
#include <cstring>
#include <algorithm>
using namespace std;
#define INF 20
#define MAX 150
int path[MAX][MAX];
int t,n;
void Floyd()
{
for(int k=; k<=n; k++)
{
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
{
if(i!=j&&path[i][j]>path[i][k]+path[k][j])
path[i][j]=path[i][k]+path[k][j];
}
}
}
int max_len,Min=INF,k=;
for(int i=; i<=n; i++)
{
max_len=;
for(int j=; j<=n; j++)
{
if(i!=j&&path[i][j]>max_len)
max_len=path[i][j];
}
if(max_len<Min)
{
Min=max_len;
k=i;
}
}
if(Min<INF)
cout<<k<<' '<<Min<<endl;
else
printf("disjoint\n");
return ;
}
int main()
{
while(cin>>n,n)
{
memset(path,INF,sizeof(path));
for(int i=; i<=n; i++)
{
scanf("%d",&t);
int a,b;
while(t--)
{
cin>>a>>b;
path[i][a]=b;
}
}
Floyd();
}
return ;
}
 
   

poj 1125 Stockbroker Grapevine(最短路径)的更多相关文章

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

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

  2. poj 1125 Stockbroker Grapevine dijkstra算法实现最短路径

    点击打开链接 Stockbroker Grapevine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 23760   Ac ...

  3. OpenJudge/Poj 1125 Stockbroker Grapevine

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

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

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

  5. POJ 1125 Stockbroker Grapevine

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

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

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

  7. Poj 1125 Stockbroker Grapevine(Floyd算法求结点对的最短路径问题)

    一.Description Stockbrokers are known to overreact to rumours. You have been contracted to develop a ...

  8. POJ 1125 Stockbroker Grapevine 最短路 难度:0

    http://poj.org/problem?id=1125 #include <iostream> #include <cstring> using namespace st ...

  9. POJ 1125 Stockbroker Grapevine(floyd)

    http://poj.org/problem?id=1125 题意 : 就是说想要在股票经纪人中传播谣言,先告诉一个人,然后让他传播给其他所有的经纪人,需要输出的是从谁开始传播需要的时间最短,输出这个 ...

随机推荐

  1. Kafka基本使用

    Kafka基本使用 官网地址  http://kafka.apache.org/   一切应以官网文档为准. 安装 download里下载要安装的版本.或者直接wget该网址.如wget http:/ ...

  2. gearman中worker常驻后台,导致MySQL server has gone away

    产生这个原因主要有如下几点: 1.mysql服务宕机了 2.长时间没有操作,超过了wait_timeout的设置,mysql自动断开 3.mysql请求链接被主动kill 4.发送的请求或返回结果过大 ...

  3. 16.Mysql SQL Mode

    16.SQL Mode及相关问题SQL Mode定义了Mysql支持的SQL语法和数据校验级别,Mysql支持多种SQL Mode.用途: 设置不同的SQL Mode可以对数据进行不同严格程度的校验, ...

  4. html标签三

    1.下拉框和下拉表框 <select name="" id="" multiple> <option value="xx" ...

  5. PAT 1011 A+B和C (15)(C++&JAVA&Python)

    1011 A+B和C (15)(15 分) 给定区间[-2^31^, 2^31^]内的3个整数A.B和C,请判断A+B是否大于C. 输入格式: 输入第1行给出正整数T(<=10),是测试用例的个 ...

  6. Luogu 2575 高手过招-SG函数

    Solution SG函数跑一遍就过了ouo Code #include<cstring> #include<cstdio> #include<algorithm> ...

  7. c# 反编译后窗口控件在vs中打不开的修改方法

    DialogResult.Cancel System.Windows.Forms.DialogResult.Cancel DialogResult.OK System.Windows.Forms.Di ...

  8. 一种基于URL数据源的WEB报表插件

    完全支持所见所得的报表设计, 支持 PHP ,Java 等所有支持JSON格式的后端. 立即下载测试版本 需要正式版本?请QQ联系:1565498246 或者留言

  9. tp5查看版本

    5.0 base.php 5.1 echo \think\facade\App::version();//用这行代码查看版本

  10. Spring ConversionService 类型转换(二) ConversionService

    Spring ConversionService 类型转换(二) ConversionService Spring 系列目录(https://www.cnblogs.com/binarylei/p/1 ...