链接:



Stockbroker Grapevine
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 23440   Accepted: 12854

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


题意:


       问怎么散播谣言最快

      每个人只可以和他们的朋友们散播谣言

      第一行给你 N 个人 【人的编号 1...N】

      剩下 N 行

      每一行第一个数num代表这个人有多少个朋友,

      剩下 num 对数分别代表朋友的编号, 和传消息到这个朋友那儿去的时间

      输出能最快传播谣言的人的编号和时间

算法:floyd简单应用


思路:


          直接套用floyd后,看哪个人传播谣言的最远距离是最小的就好了

code:


1125 Accepted 124K 0MS C++ 1362B

/**********************************************************************
Accepted 124K 0MS C++ 1362B
题意:问怎么散播谣言最快
每个人只可以和他们的朋友们散播谣言
第一行给你 N 个人 【人的编号 1...N】
剩下 N 行
每一行第一个数num代表这个人有多少个朋友,
剩下 num 对数分别代表朋友的编号, 和传消息到这个朋友那儿去的时间
输出能最快传播谣言的人的编号和时间
算法:floyd简单应用
思路:直接套用floyd后,看哪个人传播谣言的最远距离是最小的就好了
*************************************************************************/
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; const int maxn = 110;
const int INF = maxn*10; int w[maxn][maxn];
int n; void floyd()
{
for(int k = 1; k <= n; k++)
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
w[i][j] = min(w[i][j], w[i][k]+w[k][j]);
} int main()
{
while(scanf("%d", &n) != EOF)
{
if(n == 0) break; for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
w[i][j] = (i == j ? 0 : INF);
} int num;
for(int i = 1; i <= n; i++)
{
scanf("%d", &num);
int v,t;
while(num--)
{
scanf("%d%d", &v,&t);
w[i][v] = min(w[i][v], t);
}
} floyd();
int Min = INF;
int index = 1;
for(int i = 1; i <= n; i++)
{
int Max = 0;
for(int j = 1; j <= n; j++)
{
Max = max(Max, w[i][j]);
} if(Max < Min)
{
Min = Max;
index = i;
}
}
if(Min == INF) printf("disjoint\n");
else printf("%d %d\n", index, Min); }
return 0;
}
















POJ 1125 Stockbroker Grapevine【floyd简单应用】的更多相关文章

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

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

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

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

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

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

  4. OpenJudge/Poj 1125 Stockbroker Grapevine

    1.链接地址: http://poj.org/problem?id=1125 http://bailian.openjudge.cn/practice/1125 2.题目: Stockbroker G ...

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

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

  6. POJ 1125 Stockbroker Grapevine

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

  7. poj 1125 Stockbroker Grapevine dijkstra算法实现最短路径

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

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

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

  9. POJ 1125 Stockbroker Grapevine(floyd)

    http://poj.org/problem?id=1125 题意 : 就是说想要在股票经纪人中传播谣言,先告诉一个人,然后让他传播给其他所有的经纪人,需要输出的是从谁开始传播需要的时间最短,输出这个 ...

随机推荐

  1. ajax--百度百科

    AJAX即“Asynchronous Javascript And XML”(异步JavaScript和XML),是指一种创建交互式网页应用的网页开发技术. AJAX = 异步 JavaScript和 ...

  2. Qt Creator项目中使用qss

    近期学习qt .使用的编译器是qt creator ,学习过程中遇到的题就是 怎样将程序中将要用到的.qss 文件静态编译到.exe程序中,而不是在程序执行时动态加载.动态加载的最大问题在于一旦.qs ...

  3. 【Python3 爬虫】01_简单页面抓取

    运行平台:Winodows 10 Python版本:Python 3.4.2 IDE:Sublime text3 网络爬虫 网络爬虫,也叫网络蜘蛛(Web Spider),如果把互联网比喻成一个蜘蛛网 ...

  4. 使用AVPlayer制作一个播放器

    代码地址如下:http://www.demodashi.com/demo/11685.html AVPlayer 是一个强大的视频播放器,可以播放多种格式的视频,缺点是没有控制界面,需要自己去实现. ...

  5. 檢查php文件中是否含有bom的php文件

    原文链接: http://www.cnblogs.com/Athrun/archive/2010/05/27/1745464.html 另一篇文章:<关于bom.php>,http://h ...

  6. Spring AOP事务管理(使用切面把事务管理起来)

    在<Spring Transaction 分析事务属性(事务的基本概念.配置)>基础上 http://blog.csdn.net/partner4java/article/details/ ...

  7. Docker 方式运行 jenkins

    原文地址:https://testerhome.com/topics/5798 简介说明 docker 是官方推荐的一种 jenkins 启动方式. 打开 jenkins 的官网,点击进入的是: ht ...

  8. Git使用笔记2

    工作必备: [更新master] git checkout master git pull git checkout zyb/FirstCommit git merge master //git re ...

  9. JDK1.9环境变量配置

    JAVA_HOME C:\Program Files\Java\jdk-9.0.1 JRE_HOME C:\Program Files\Java\jre-9.0.1 PATH .;%JAVA_HOME ...

  10. NativeViewer for VS2010

    记得非常久之前公布了一款能够在调试中可视化Mat数据的插件,只是仅仅能用于VS2012及以上.我用的是VS2010(笔记本跑10都卡的不得了,12不敢奢望),不免有些遗憾.非常高兴的say如今这个问题 ...