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. OO第1~3次作业总结

    作业1——多项式运算 基于度量和类图分析设计 先看Metrics插件做出的复杂度分析: 乍一看没有红色报警,其实是因为选中某一行时会自动将该行改为黑色,无论之前是红色还是蓝色emmm 真正展开第一行时 ...

  2. 相亲神器记录Swift1.2

    这个简单APP是用swfit1.2写的,主要重点是:1.点击键盘return键可退出键盘. 2.各个控件值的传递. Storyboard界面设计: View代码: import UIKit class ...

  3. 2PC AND 3PC

    一.分布式数据一致性 在分布式系统中,为了保证数据的高可用,通常会将数据保留多个副本(replica),这些副本会放置在不同的物理的机器上. (1)什么是数据一致性 在数据有多份副本的情况下,如果网络 ...

  4. 软件设计、DDD概念及落地时的一些零碎思考和记录2

    主要是项目中一些落地经验和记录 技术人员.开发人员 大部分程序员真的不善于沟通,经常会显得很保守: 他们技术上的困惑.误解乃至郁闷都很难直接的表达清楚: 他们对自己的错误"印象"很 ...

  5. 20155217《网络对抗》Exp08 Web基础

    20155217<网络对抗>Exp08 Web基础 实践内容 Web前端:HTML基础 Web前端:javascipt基础 Web后端:MySQL基础 Web后端:PHP基础 SQL注入 ...

  6. Android开发——监听Android手机的网络状态

    0. 前言 在Android开发中监听手机的网络状态是一个常见的功能,比如在没网的状态下进行提醒并引导用户打开网络设置,或者在非wifi状态下开启无图模式等等.因此本篇将网上的资料进行了整理总结,方便 ...

  7. [CF1009G]Allowed Letters[贪心+霍尔定理]

    题意 给你一个长为 \(n\) 的串,字符集为 \(a,b,c,d,e,f\) .你可以将整个串打乱之后重新放置,但是某些位置上有一些限制:必须放某个字符集的字符.问字典序最小的串,如果无解输出 &q ...

  8. PowerBI开发 第一篇:设计PowerBI报表

    PowerBI是微软新一代的交互式报表工具,把相关的静态数据转换为酷炫的可视化的,能够根据filter条件,对数据执行动态筛选,从不同的角度和粒度上分析数据.PowerBI主要由两部分组成:Power ...

  9. stl源码剖析 详细学习笔记deque(2)

    //---------------------------15/3/13---------------------------- self&operator++() { ++cur; if(c ...

  10. 机器学习英雄访谈录之 DL 实践家:Dominic Monn

    目录 机器学习英雄访谈录之 DL 实践家:Dominic Monn 正文 对我的启发 机器学习英雄访谈录之 DL 实践家:Dominic Monn Sanyam Bhutani 是 Medium 上一 ...