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. jqgrid 自定义添加行数据

    一般在设置了自定义按钮后,比如‘添加’按钮,点击添加需要添加一条数据在表格中. 通过jqgrid的方法 addRowData 插入一行数据. //添加一行数据 function addRow() { ...

  2. C 语言的关键字static 和C++ 的关键字static 有什么区别

    C 中static 用来修饰局部静态变量和外部静态变量.函数. C++中除了上述功能外,还用来定义类的成员变量和函数.即静态成员和静态成员函数. 注意:编程时 static的记忆性,和全局性的特点可以 ...

  3. Python3入门(九)——面向对象OOP高级编程

    一.使用__slots__限制属性绑定 动态绑定实例的方法: class Person(object): def run(self): print("奔跑吧!") p1 = Per ...

  4. 20155223 实验5 MSF基础应用

    20155223 实验5 MSF基础应用 基础问题回答 用自己的话解释什么是exploit,payload,encode? exploit:漏洞攻击.一个exploit程序肯定会触发系统的一个或多个漏 ...

  5. python基础学习1-列表使用

    python 列表相关操作方法 namelist = ['a','b','c','d','1','2','3','4'] namelist1 = ['a','b','c','d','1','2','3 ...

  6. python 带参数的多重继承

    1. 不带参数的多重继承 # 作者:hhh5460 # 时间:2017.07.18 class A(object): def show_x(self): print('A') class B(obje ...

  7. Kubernetes学习之路(二十)之K8S组件运行原理详解总结

    目录 一.看图说K8S 二.K8S的概念和术语 三.K8S集群组件 1.Master组件 2.Node组件 3.核心附件 四.K8S的网络模型 五.Kubernetes的核心对象详解 1.Pod资源对 ...

  8. 搭建 Guacamole 并解决各种坑和创建不了虚拟驱动器导致无法实现文件传输的方法

    系统类型版本:centos7 64位 结果:最终跑通了项目并且实现了虚拟驱动器的文件传输功能,添加了中文支持 反思总结: 先查看官方文档的Q&A,找找有没有类似的错误,然后如果有错误日志或者现 ...

  9. Java中的Calendar日历用法详解

    第一部分 Calendar介绍 public abstract class Calendar implements Serializable, Cloneable, Comparable<Cal ...

  10. 爱普生L313彩色打印相片

    操作环境: windows 和MAC 一.普通打印(默认选项) 1.爱普生L313 普通默认打印为快速不清晰打印. 2.以上打印效果出来图片比较快速出图,但是清晰度不够 二.照片打印设置 1.照片设置 ...