描述

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 0x3f3f3f3f int N;
int map[MAXN][MAXN];
int ans[MAXN]; void floyd(){
for(int k=; k<=N; k++){
for(int i=; i<=N; i++){
for(int j=; 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=; i<=N; i++){
for(int j=; j<=N; j++){
if(i==j)map[i][j]=;
else map[i][j]=inf;
}
}
for(int u=; u<=N; u++){
scanf("%d",&t);
while(t--){
scanf("%d %d",&v,&w);
map[u][v]=w;
}
ans[u]=-;
}
floyd();
for(int i=; i<=N; i++){
for(int j=; j<=N; j++){
if(map[i][j]>ans[i])ans[i]=map[i][j];
}
}
int min=inf,index;
for(int i=; 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 ;
}

TOJ 2857 Stockbroker Grapevine的更多相关文章

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

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

  2. POJ 1125 Stockbroker Grapevine

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

  3. Stockbroker Grapevine(floyd)

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

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

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

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

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

  6. OpenJudge/Poj 1125 Stockbroker Grapevine

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

  7. 【POJ 1125】Stockbroker Grapevine

    id=1125">[POJ 1125]Stockbroker Grapevine 最短路 只是这题数据非常水. . 主要想大牛们试试南阳OJ同题 链接例如以下: http://acm. ...

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

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

  9. Stockbroker Grapevine(最短路)

      poj——1125 Stockbroker Grapevine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 36112 ...

随机推荐

  1. 如何较为方便的在GMap.Net中实现车辆运行轨迹

    一.简单的思路 要实现车辆运行轨迹,我们可能需要一个定时触发的机制用来更新Marker的位置,除了位置移动,我们可能还需要动态改变车辆的方向,如下图: 首先,位置移动是最简单的,关键是方向的动态改变如 ...

  2. c# 根据文件夹或文件名返回(文件夹或文件)的完整路径

    c#  根据文件夹或文件名返回(文件夹或文件)的完整路径 一.方案一:(使用windows API) 二.方案二:(扫描全盘)

  3. 有符号数和无符号数------c++程序设计原理与实践(进阶篇)

    有符号数与无符号数的程序设计原则: 当需要表示数值时,使用有符号数(如 int). 当需要表示位集合时,使用无符号数(如unsigned int). 有符号数和无符号数混合运算有可能会带来灾难性的后果 ...

  4. 离线安装 python 第三方库

     离线安装 python 第三方库 首先你需要在联网的服务器上已经安装了一个第三方库,比如是paramiko,也就是说你已经执行了 pip install paramiko    ,小提示: 如果在安 ...

  5. 生成HTML测试报告

    HTMLTestRunner是Python标准库unittest单元测试框架的一个扩展,可以生成易于使用的HTML测试报告,这个扩展很简单,只有一个HTMLTestRunner.py,下载地址:htt ...

  6. 网站Seo纲领

    1:准备工作和内容来源 2:域名注册 3:网站设计越简单越好 4:内容长度 5:四处一词 6:站内定向锚文本 7:内容编辑标准 8:外链建设 9:日志分析能力 10:更新频率和高质量的内容 1:准备工 ...

  7. 【bzoj4007】[JLOI2015]战争调度 暴力+树形dp

    Description 脸哥最近来到了一个神奇的王国,王国里的公民每个公民有两个下属或者没有下属,这种 关系刚好组成一个 n 层的完全二叉树.公民 i 的下属是 2 * i 和 2 * i +1.最下 ...

  8. dsp之BF531笔记

    获得更多资料欢迎进入我的网站或者 csdn或者博客园 很久以前的BF531的笔记,觉得有用分享出来.摘自于open dsp 通用Gpio ADSP-BF53x 处理器上有16 个PF 接口,这些接口就 ...

  9. http2.2使用ajp与tomcat集成

    环境 1.CENTOS 6.5 2.yun安装的httpd,版本是2.2 3.tomcat版本8.5.28 操作 关闭8080端口连接,打开8009端口修改tomcat_home/conf/serve ...

  10. 分享记录一批免费VIP视频解析接口,不定时更新!

    VIP视频接口的作用相信大家都懂,那么,由于接口的维护.开发具有不稳定性,失效率很高.这里收集一些目前可用的接口,如果不能用,请反馈给我删除,感谢大家! 电影<西虹市首富>优酷链接:htt ...