描述

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.

输入

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.

输出

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.

样例输入

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

样例输出

3 2
3 10

题目来源

Southern African 2001

求一个Stockbroker把消息传递给其他Stockbroker所用的最短时间。

floyd求出两点之间消息传递的时间后,再求最短时间。

#include <stdio.h>
#define MAXN 105
#define inf 0x3f3f3f3fint N;
int map[MAXN][MAXN];
int ans[MAXN];void floyd(){for(int k=1; k<=N; k++){for(int i=1; i<=N; i++){for(int j=1; j<=N; j++){if(i==k||i==j)continue;if(map[i][k]!=inf && map[k][j]!=inf &&map[i][k]+map[k][j]<map[i][j]){map[i][j]=map[i][k]+map[k][j];}}}}
}
int main(int argc, char *argv[])
{int t,u,v,w;while(scanf("%d",&N)!=EOF && N){for(int i=1; i<=N; i++){for(int j=1; j<=N; j++){if(i==j)map[i][j]=0;else map[i][j]=inf;}}for(int u=1; u<=N; u++){scanf("%d",&t);while(t--){scanf("%d %d",&v,&w);map[u][v]=w;}ans[u]=-1;}floyd();for(int i=1; i<=N; i++){for(int j=1; j<=N; j++){if(map[i][j]>ans[i])ans[i]=map[i][j];}}int min=inf,index;for(int i=1; i<=N; i++){if(ans[i]<min){min=ans[i];index=i;}}if(min==inf){printf("disjoint\n");}else{printf("%d %d\n",index,min);}}return 0;
}

转载于:https://www.cnblogs.com/chenjianxiang/p/3534627.html

TOJ 2857 Stockbroker Grapevine相关推荐

  1. POJ 1125 Stockbroker Grapevine

    题意:有n个人,传播谣言,每个人向其他人传播的时间作为边权,构成一个有向图,问把谣言告诉谁能最快传到所有人,输出这个人和最短时间. 解法:最短路.一个人传到所有人的最短时间即他到所有人最短路的最大值, ...

  2. poj1125 Stockbroker Grapevine Floyd算法

    问题描述 Stockbrokers are known to overreact to rumours. You have been contracted to develop a method of ...

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

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

  4. POJ-1125 Stockbroker Grapevine 最短路

    这题要处理的地方的就是一个人可以同时向多个人传递消息,也就是说一条消息的传递时间由最长的那一条路径所决定,因为可以同时进行嘛,所以就求某一点到所有点的最短路,然后再寻找一条最长的路劲,枚举每个顶点作为 ...

  5. poj 1125 Stockbroker Grapevine(Folyd)

    1 //nyoj的数据改成了1000 ,然后就跪了.. 好像大神们用spfa做的 2 #include<iostream> 3 #include<cstdio> 4 #incl ...

  6. 一步一步深入理解Dijkstra算法

    先简单介绍一下最短路径: 最短路径是啥?就是一个带边值的图中从某一个顶点到另外一个顶点的最短路径. 官方定义:对于内网图而言,最短路径是指两顶点之间经过的边上权值之和最小的路径. 并且我们称路径上的第 ...

  7. 【HDOJ图论题集】【转】

    1 =============================以下是最小生成树+并查集====================================== 2 [HDU] 3 1213 How ...

  8. 一系列图论问题[转]

    =============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...

  9. 【转载】图论 500题——主要为hdu/poj/zoj

    转自--http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

最新文章

  1. VCenter电源报警
  2. language wars
  3. 【webservice】spring整合webservice RS风格
  4. jboss mysql cluster_为JBoss AS 7配置Mysql数据源
  5. Docker框架的使用系列教程(四)容器的使用
  6. ubuntu16.04 python3.5 opencv的安装与卸载(转载)
  7. 如何使用Gitbook创建html技术文档
  8. mysql语句修改zencart产品原价为特价的倍数
  9. InvalidClassException: org.antlr.v4.runtime.atn.ATN; Could not deserialize ATN with UUID
  10. 正态分布的概率密度函数python_python绘制正态分布及三大抽样分布的概率密度图像...
  11. HTTP权威指南------1.1HTTP概述
  12. 微信群发红包原理 计算机,微信红包实现原理探讨
  13. 高通败诉,授权专利技术之后高通的优势不再?
  14. Android小钢琴
  15. OpenJudge-005雇佣兵(解析)
  16. Z05 - 006、网站转化以及漏斗分析(转化分析)
  17. 2021多益网络春季校园招聘游戏研发笔试题(回忆版)
  18. PYNQ入门(2)——启动系统及例程查看
  19. 龙蜥社区技术委员会主席杨勇:下一代操作系统展望
  20. DB-数据库基本概念(一)

热门文章

  1. oracle查询表的id,oracle 查看所有用户及密码 实现Oracle查询用户所有表
  2. Win32ASM学习[17]:条件跳转
  3. linux虚拟机ip修改无效
  4. linux操作系统进程间通信IPC之共享存储映射
  5. QString中包含中文的时候, 转为char *
  6. C++ 标准输入流01
  7. 科技论文----论搜索引擎现状及发展趋势
  8. shell生成随机文件名
  9. UVA - 12096:The SetStack Computer
  10. Linux网络编程“惊群”问题总结