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 思路:
先用最短路找一下i-j的最短路径,然后只要找到第i个经纪人的的最长路径也就是最晚接到消息的时间,这就是这个经纪人的耗时,只要比较下所有经济人中耗时最短的就是我们要找的。
至于不连通的这个很容易解决,只要初始化给每条路径一个初始的值(一个很大的数字),floyd之后只要再遍历一遍i经纪人的最长路径,如果他的最长路径是初始值的话,说明有路径
没有连通,直接输出disjoint就好了。这只是数据比较小可以用floyd解决,如果数据比较大的话还好,还是要用其他耗时比较低的算法,比如spfa算法。 实现代码:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define INF 0x3f3f3f3f
#define maxx 9999999
int mp[][],n;
void floyd(){
for(int i = ;i <= n; i++){
for(int j = ;j <= n; j++){
for(int k = ;k <= n; k++){
if(mp[j][k] > mp[j][i]+mp[i][k])
mp[j][k] = mp[j][i] + mp[i][k];
}
}
}
}
int main()
{
int i,j,minn,minx,m,x,y;
while(scanf("%d",&n)&&n){
minn = maxx;
for(i=;i<=n;i++)
for(j=;j<=n;j++)
mp[i][j] = mp[j][i] = maxx;
for(i=;i<=n;i++){
scanf("%d",&m);
while(m--){
scanf("%d%d",&x,&y);
mp[i][x] = y;
}
}
floyd();
for(i=;i<=n;i++){
int ans = ;
for(j=;j<=n;j++){
if(i!=j&&mp[i][j]>ans)
ans = mp[i][j];
}
if(ans<minn){
minn = ans;
minx = i;
}
}
if(minn == maxx) cout<<"disjoint"<<endl;
else cout<<minx<<" "<<minn<<endl;
memset(mp,INF,sizeof(mp));
}
}
 

POJ 1125 Stockbroker Grapevine(最短路基础题)的更多相关文章

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

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

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

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

  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 dijkstra算法实现最短路径

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

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

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

  7. POJ 1125 Stockbroker Grapevine

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

  8. poj 1125 Stockbroker Grapevine(最短路 简单 floyd)

    题目:http://poj.org/problem?id=1125 题意:给出一个社交网络,每个人有几个别人可以传播谣言,传播谣言需要时间.问要使得谣言传播的最快,应该从那个人开始传播谣言以及使得所有 ...

  9. POJ 1125 Stockbroker Grapevine (Floyd最短路)

    Floyd算法计算每对顶点之间的最短路径的问题 题目中隐含了一个条件是一个人能够同一时候将谣言传递给多个人 题目终于的要求是时间最短.那么就要遍历一遍求出每一个点作为源点时,最长的最短路径长是多少,再 ...

随机推荐

  1. zabbix items 配置

    item是什么?它是我们对于host监控的基本条目,它属于不同的applications中,item的设置既可以针对具体的某个host主机,也可以针对模板进行设定(可以在多个主机进行复用). item ...

  2. jqgrid 让隐藏的列在编辑状态时出现且可编辑

    有时,我们需要隐藏一个列数据,但在启动编辑时又能够被编辑. 1.设置列为编辑:editable: true 2.设置 editrules属性值为: edithidden: true colModel: ...

  3. 从裸机编程到嵌入式Linux编程思想的转变------分而治之:驱动和应用程序

    笔者学习嵌入式Linux也有一段时间了,很奇怪的是很多书讲驱动编程方面的知识,也有很多书将ARM9方面的知识,但是从以前51形式的(对寄存器直接操作,初始化芯片的功能模块)编程方法,和思维模式,变换为 ...

  4. 使用target打开的iframe 获取src的问题

    <a target="mainframe"href="xxx.jsp"/> <iframe id="mainframe" ...

  5. 20155202张旭《网络对抗技术》 week1 PC平台逆向破解及Bof基础实践

    20155202张旭<网络对抗技术> week1 PC平台逆向破解及Bof基础实践 1.实践目标: 实践对象:一个名为pwn1的linux可执行文件. 该程序正常执行流程是: main调用 ...

  6. python 回溯法 子集树模板 系列 —— 8、图的遍历

    问题 一个图: A --> B A --> C B --> C B --> D B --> E C --> A C --> D D --> C E -- ...

  7. ajax传递数组给controller的实现方法和坑

    这里是前端向后端传递一个数组的方式,参考下面这个示例: (主要是将前端的数组,用 JSON.stringify() 方法json化一下,然后后端springmvc接收到以后,使用 JSONArray  ...

  8. TFS2012独占签出设置

    说明:TFS2012默认是可以多人签出同一个文件.如果要设为独占签出,请看下面操作步骤 1. 2. 3. 然后选择工作区---编辑---高级.最后如下图,在位置那里选择服务器. END

  9. Partition3:分区切换(Switch)

    在SQL Server中,对超级大表做数据归档,使用select和delete命令是十分耗费CPU时间和Disk空间的,SQL Server必须记录相应数量的事务日志,而使用switch操作归档分区表 ...

  10. docker之容器管理

    一.docker常用的创建命令 [root@node03 ~]# docker create --help [root@node03 ~]# docker run --help OPTIONS说明: ...