Stockbroker Grapevine
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 28231   Accepted: 15659

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

 #include<stdio.h>
#include<string.h>
const int inf = 0x3f3f3f3f , M = ;
int d[M] ;
int map[M][M] ;
int n ; int main ()
{
//freopen ("a.txt" , "r" , stdin) ;
int x , v , t ;
while (~ scanf ("%d" , &n)) {
if (n == )
break ;
for (int i = ; i <= n ; i++) {
for (int j = ; j <= n ; j++) {
map[i][j] = inf ;
}
}
for (int i = ; i <= n ; i++) {
scanf ("%d" , &x) ;
while (x--) {
scanf ("%d%d" , &v , &t) ;
map[i][v] = t ;
}
}
for (int k = ; k <= n ; k++) {
for (int i = ; i <= n ; i++) {
for (int j = ; j<= n ; j++) {
if (map[i][k] + map[k][j] < map[i][j] && i != j)
map[i][j] = map[i][k] + map[k][j] ;
}
}
}
int maxn ;
for (int i = ; i <= n ; i++) {
maxn = - ;
for (int j = ; j <= n ; j++) {
if (i != j && maxn < map[i][j])
maxn = map[i][j] ;
}
d[i] = maxn ;
}
int minn = inf, k;
for (int i = ; i <= n ; i++) {
if (minn > d[i]) {
minn = d[i] ;
k = i ;
}
}
if (minn == inf)
puts ("disjoint") ;
else
printf ("%d %d\n" , k , minn) ;
}
return ;
}

floyd算法写法上很简单,适合多源最短路径发

Stockbroker Grapevine(floyd)的更多相关文章

  1. Stockbroker Grapevine(floyd+暴力枚举)

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

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

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

  3. poj1125 Stockbroker Grapevine Floyd

    题目链接:http://poj.org/problem?id=1125 主要是读懂题意 然后就很简单了 floyd算法的应用 代码: #include<iostream> #include ...

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

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

  5. Southern African 2001 Stockbroker Grapevine /// Floyd oj1345

    题目大意: 输入n 接下来n行 每行输入m 接下来m对a,b 若干个人之间会传播谣言,但每个人传播给其他人的速度都不一样, 问最快的传播路线(即耗时最短的)中最耗时的一个传播环节. 如果其中有人不在这 ...

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

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

  7. Stockbroker Grapevine POJ 1125 Floyd

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

  8. poj1125&zoj1082Stockbroker Grapevine(Floyd算法)

    Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Description Stockbrokers are known to ...

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

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

随机推荐

  1. Expression 表达式树学习整理

    整理了一下表达式树的一些东西,入门足够了 先从ConstantExpression 开始一步一步的来吧  它表示具有常量值的表达式 我们选建一个控制台应用程序 ConstantExpression _ ...

  2. Android四大布局及其主要属性

    布局: <LinearLayout></LinearLayout> <RelativeLayout></RelativeLayout> <Fram ...

  3. [软件测试]Linux环境中简单清爽的Google Test (GTest)测试环境搭建(初级使用)

    本文将介绍单元测试工具google test(GTEST)在linux操作系统中测试环境的搭建方法.本文属于google test使用的基础教程.在linux中使用google test之前,需要对如 ...

  4. 基于int的Linux的经典系统调用实现

     先说明两个概念:中断和系统调用 一 系统调用: 是应用程序(运行库也是应用程序的一部分)与操作系统内核之间的接口,它决定了应用程序是如何和内核打交道的. 1,  Linux系统调用:2.6.19版内 ...

  5. 自定义带图片和文字的ImageTextButton

    今天我们来讲一下有关自定义控件的问题,今天讲的这篇是从布局自定义开始的,难度不大,一看就明白,估计有的同学或者开发者看了说,这种方式多此一举,但是小编我不这么认为,多一种解决方式,就多一种举一反三的学 ...

  6. (旧)子数涵数·Flash——遮罩动画

    一.打开Flash,并新建一个flash文档 二.然后,用矩形工具,快捷键R,绘制一个背景图 三.新建一个图层 四.右击刚刚新建的"图层2"图层,选择"遮罩层" ...

  7. sql server 数据库备份,完整备份,差异备份,自动备份说明

    Sql server 设置完整备份,差异备份说明 在数据库管理器中,选择要备份的数据库,右键找到“备份” 然后可以按照备份的方式进行备份. 关于文件的还原,作以下补充说明: 步骤为: 1.在需要还原的 ...

  8. Matrix67大牛推荐的省选知识点

    时间复杂度(渐近时间复杂度的严格定义,NP问题,时间复杂度的分析方法,主定理)排序算法(平方排序算法的应用,Shell排序,快速排序,归并排序,时间复杂度下界,三种线性时间排序,外部排序)数论(整除, ...

  9. linux中的帮助命令

    关键字 man --help help 1.man (1)查看命令 man 命令用来查看别的命令的信息和用法,如man ls表示查看ls的介绍以及用法: (2)查看配置文件的帮助文档 linux下的配 ...

  10. Symfony学习--目录和入口

    1 目录结构 根目录下有: app src vendor web app是存放应用的一些配置文件,如果有一些配置文件或者文档,应当存放在这里面. src是存放你的项目的php代码,这里的php至少必须 ...