POJ 1125 Stockbroker Grapevine
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 33141 | Accepted: 18246 |
Description
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
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
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个股票经济人可以互相传递消息,他们之间存在一些单向的通信路径。现在有一个消息要由某个人开始传递给其他所有人,问应该由哪一个人来传递,才能在最短时间内让所有人都接收到消息。若不存在这样一个人,则输出disjoint
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
#define N 101
int a[N][N],n,m;
int main(){
while(scanf("%d",&n)==&&n){
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
if(i==j) a[i][j]=;
else a[i][j]=;
for(int i=;i<=n;i++){
scanf("%d",&m);
for(int j=,v,w;j<=m;j++){
scanf("%d%d",&v,&w);
a[i][v]=w;
}
}
for(int k=;k<=n;k++)
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
if(i!=j&&i!=k&&k!=j)
if(a[i][j]>a[i][k]+a[k][j])
a[i][j]=a[i][k]+a[k][j];
int ans=0x7f,p;
for(int i=;i<=n;i++){
int m=-0x7f;
for(int j=;j<=n;j++)
m=max(m,a[i][j]);
if(ans>m){
ans=m;
p=i;
}
}
printf("%d %d\n",p,ans);
}
return ;
}
POJ 1125 Stockbroker Grapevine的更多相关文章
- 最短路(Floyd_Warshall) POJ 1125 Stockbroker Grapevine
题目传送门 /* 最短路:Floyd模板题 主要是两点最短的距离和起始位置 http://blog.csdn.net/y990041769/article/details/37955253 */ #i ...
- OpenJudge/Poj 1125 Stockbroker Grapevine
1.链接地址: http://poj.org/problem?id=1125 http://bailian.openjudge.cn/practice/1125 2.题目: Stockbroker G ...
- POJ 1125 Stockbroker Grapevine【floyd简单应用】
链接: http://poj.org/problem?id=1125 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
- poj 1125 Stockbroker Grapevine dijkstra算法实现最短路径
点击打开链接 Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 23760 Ac ...
- poj 1125 Stockbroker Grapevine(多源最短)
id=1125">链接:poj 1125 题意:输入n个经纪人,以及他们之间传播谣言所需的时间, 问从哪个人開始传播使得全部人知道所需时间最少.这个最少时间是多少 分析:由于谣言传播是 ...
- POJ 1125 Stockbroker Grapevine 最短路 难度:0
http://poj.org/problem?id=1125 #include <iostream> #include <cstring> using namespace st ...
- POJ 1125 Stockbroker Grapevine(floyd)
http://poj.org/problem?id=1125 题意 : 就是说想要在股票经纪人中传播谣言,先告诉一个人,然后让他传播给其他所有的经纪人,需要输出的是从谁开始传播需要的时间最短,输出这个 ...
- poj 1125 Stockbroker Grapevine(最短路 简单 floyd)
题目:http://poj.org/problem?id=1125 题意:给出一个社交网络,每个人有几个别人可以传播谣言,传播谣言需要时间.问要使得谣言传播的最快,应该从那个人开始传播谣言以及使得所有 ...
- Poj 1125 Stockbroker Grapevine(Floyd算法求结点对的最短路径问题)
一.Description Stockbrokers are known to overreact to rumours. You have been contracted to develop a ...
随机推荐
- 【原】UI随设备旋转从iOS6到iOS8的适配策略
- (void)statusBarOrientationChange:(NSNotification *)notification { WClassAndFunctionName; UIInterfa ...
- C语言。自定义函数简单版
#include <stdio.h> //函数声明 void sayHi(); //函数实现 void sayHI() { printf("大家好!!\n"); } i ...
- Java 之 内部类
(static修饰的成员属于整个类,而不属于单个对象) 定义:将一个类放到另一个类的内部定义,这个在内部定义的类就叫做内部类(也有的成嵌套类),包含内部类的类被称为外部类(也有的称宿主类). 1.非静 ...
- 21分钟 MySQL 入门教程
目录 一.MySQL的相关概念介绍 二.Windows下MySQL的配置 配置步骤 MySQL服务的启动.停止与卸载 三.MySQL脚本的基本组成 四.MySQL中的数据类型 五.使用MySQL数据库 ...
- 记录ubuntu下的svn一些操作
1.install svn serversudo apt-get install subversion 2.make repositorysudo mkdir /home/.svnsudo mkdie ...
- 安装concrete时提示“...database does not support InnoDB database tables..."如何解决
安装很多系统时,经常有有提示: "...database does not support InnoDB database tables..." 解决办法: 找到MySQL的配置文 ...
- Windows下查看端口占用
最近在重新安装Mysql的时候,发现3306默认端口被占用了.类似的情况常常遇到,想查看到底是哪个程序把这个端口占用了. 下面是我google找到的方法,和大家分享. 1. 首先,使用netstat ...
- Hadoop从伪分布式到真正的分布式
对这两天学习hadoop的一个总结,概念就不提了.直接说部署的事,关于如何部署hadoop网上的资料很多, 比较经典的还是Tim在IBM developworks上的系列文章 http://www.i ...
- 读书摘要:第七章 闩Suan锁和自旋锁
摘要: 1.闩锁就像是内存上的锁,随着越来越多的线程参与进来,他们争相访问同一块内存,导致堵塞.2.自旋锁就是闩锁,不同之处是如果访问的内存不可用,它将继续检查轮询一段时间.3.拴锁和自旋锁是我们无法 ...
- Eclipse EE 发布项目导致 Tomcate 的配置文件 server.xml 还原
在server.xml中配置SSL时,发现了每次发布项目都导致server.xml被还原了: <Connector port="8443" protocol="or ...