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. Python爬虫项目--爬取猫眼电影Top100榜

    本次抓取猫眼电影Top100榜所用到的知识点: 1. python requests库 2. 正则表达式 3. csv模块 4. 多进程 正文 目标站点分析 通过对目标站点的分析, 来确定网页结构,  ...

  2. 24-算法训练 删除数组零元素-- list的使用

    http://lx.lanqiao.cn/problem.page?gpid=T201 算法训练 删除数组零元素   时间限制:1.0s   内存限制:512.0MB      从键盘读入n个整数放入 ...

  3. ERROR: APK path is not specified for

    1. 打开project structure 2.设置outpath路径 最好为绝对路径 点击确定  重新编译即可. Note: Android Studio版本使用

  4. pthreads v3下的同步处理synchronized

    之所以会用到同步,是因为如果多个线程中对同一个资源进行操作时,会发生混乱. 比如2个线程对变量进行加1操作,第1个线程还没来的及改写数据时,第2个线程就对变量进行操作了,那变量最终的结果就是未知的,这 ...

  5. rbac 权限分配, 基于formset实现,批量编辑

    已经完成了  批量添加的功能. 还想要一个批量修改的功能了.随之而来的第一个问题就是,  我们的formset 并不是一条记录.而是 多条记录,甚至整个表的记录.那么显而易见的问题就是,当前端页面把数 ...

  6. Redhat ssh服务登录慢

    redhat在安装以后每次通过ssh服务登录,要等待几秒才能进入. 只要在sshd_config修改一下以下值就好 vim /etc/ssh/sshd_config UseDNS no service ...

  7. Vue v-if 和 v-show

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  8. C# Contains 包含空字符串的问题

    一个基本的条件判断,之前没有遇到,这次遇到后,感觉真是这些年白写程序了. if(("1,2,3").Contains("")) { MessageBox.Sho ...

  9. springboot中controller的使用

    一.知识点 1 @Controller 处理http请求(不推荐使用) 2 @RestController spring4之后新加的注解,原来返回json需要@ResponseBody配合@Contr ...

  10. C++中的getline()

    总结: 尽量使用全局函数string类中的getline(),其读入的第二个参数为string类型,不设置默认是遇到回车停止读入操作 cin.getline是针对数组字符串的,以指定的地址为存放第一个 ...