Stockbroker Grapevine(floyd)
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 28231 | Accepted: 15659 |
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
#include<stdio.h>
#include<string.h>
const int inf = 0x3f3f3f3f , M = ;
int d[M] ;
int map[M][M] ;
int n ; int main ()
{
//freopen ("a.txt" , "r" , stdin) ;
int x , v , t ;
while (~ scanf ("%d" , &n)) {
if (n == )
break ;
for (int i = ; i <= n ; i++) {
for (int j = ; j <= n ; j++) {
map[i][j] = inf ;
}
}
for (int i = ; i <= n ; i++) {
scanf ("%d" , &x) ;
while (x--) {
scanf ("%d%d" , &v , &t) ;
map[i][v] = t ;
}
}
for (int k = ; k <= n ; k++) {
for (int i = ; i <= n ; i++) {
for (int j = ; j<= n ; j++) {
if (map[i][k] + map[k][j] < map[i][j] && i != j)
map[i][j] = map[i][k] + map[k][j] ;
}
}
}
int maxn ;
for (int i = ; i <= n ; i++) {
maxn = - ;
for (int j = ; j <= n ; j++) {
if (i != j && maxn < map[i][j])
maxn = map[i][j] ;
}
d[i] = maxn ;
}
int minn = inf, k;
for (int i = ; i <= n ; i++) {
if (minn > d[i]) {
minn = d[i] ;
k = i ;
}
}
if (minn == inf)
puts ("disjoint") ;
else
printf ("%d %d\n" , k , minn) ;
}
return ;
}
floyd算法写法上很简单,适合多源最短路径发
Stockbroker Grapevine(floyd)的更多相关文章
- Stockbroker Grapevine(floyd+暴力枚举)
Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 31264 Accepted: 171 ...
- Poj 1125 Stockbroker Grapevine(Floyd算法求结点对的最短路径问题)
一.Description Stockbrokers are known to overreact to rumours. You have been contracted to develop a ...
- poj1125 Stockbroker Grapevine Floyd
题目链接:http://poj.org/problem?id=1125 主要是读懂题意 然后就很简单了 floyd算法的应用 代码: #include<iostream> #include ...
- POJ 1125 Stockbroker Grapevine (Floyd最短路)
Floyd算法计算每对顶点之间的最短路径的问题 题目中隐含了一个条件是一个人能够同一时候将谣言传递给多个人 题目终于的要求是时间最短.那么就要遍历一遍求出每一个点作为源点时,最长的最短路径长是多少,再 ...
- Southern African 2001 Stockbroker Grapevine /// Floyd oj1345
题目大意: 输入n 接下来n行 每行输入m 接下来m对a,b 若干个人之间会传播谣言,但每个人传播给其他人的速度都不一样, 问最快的传播路线(即耗时最短的)中最耗时的一个传播环节. 如果其中有人不在这 ...
- POJ 1125 Stockbroker Grapevine【floyd简单应用】
链接: http://poj.org/problem?id=1125 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
- Stockbroker Grapevine POJ 1125 Floyd
Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 37069 Accepted: ...
- poj1125&zoj1082Stockbroker Grapevine(Floyd算法)
Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Description Stockbrokers are known to ...
- 最短路(Floyd_Warshall) POJ 1125 Stockbroker Grapevine
题目传送门 /* 最短路:Floyd模板题 主要是两点最短的距离和起始位置 http://blog.csdn.net/y990041769/article/details/37955253 */ #i ...
随机推荐
- Ubuntu安装uget和aria2下载工具
Windows下的下载工具有迅雷,快车等.Ubuntu下也有强大的下载工具uget和aria2. 一.安装.uget和aria2都可以在“软件中心”中安装,但是版本太老啦,所以最好还是在终端中添加pp ...
- 学习笔记——Maven pom.xml配置详解
POM的全称是“ProjectObjectModel(项目对象模型)”. pom.xml详解 声明规范 <projectxmlns="http://maven.apache.org/P ...
- IIS7 IIS7.5 配置备份
IIS 7 提供了一个新的命令行工具 Appcmd.exe,可以使用该工具来配置和查询 Web 服务器上的对象,并以文本或 XML 格式返回输出. IIS 备份还原命令如下: 开始-运行-CMD 进入 ...
- 服务器网站报错:由于扩展配置问题无法提供您请求的页面,请添加MIME映射,针对mp4,flv文件类型无法打开。
确保IIS正常 服务器增加mp4格式的MIME 类型映射设置的具体步骤是: “开始” > “控制面板” > “管理工具” >“Internet 信息服务(IIS管理器)”,“MIME ...
- [USACO2005][POJ3171]Cleaning Shifts(DP+线段树优化)
题目:http://poj.org/problem?id=3171 题意:给你n个区间[a,b],每个区间都有一个费用c,要你用最小的费用覆盖区间[M,E] 分析:经典的区间覆盖问题,百度可以搜到这个 ...
- linux中的服务
一.服务分类 独立的服务比如像httpd服务,用户可以直接来访问.并且独立服务常驻内存.而xinetd服务是一个服务管理器,它是常驻内存的,它下面有很多子服务,但这些子服务并不长驻内存.当用户想要使用 ...
- [工具类]泛型集合转换为DataTable
写在前面 在实际项目中,用到了将集合转换为DataTable,就试着封装了一个方法,记录一下. 代码 using System; using System.Collections.Generic; u ...
- zabbix修改密码
在我们刚刚安装好zabbix之后我们的管理用户是 Admin,密码是zabbix 所以我们肯定是要更改密码的,这个方法也适用于我们忘记管理员密码 首先我们登录mysql数据库 这里有一个zabbix库 ...
- 小结-Splay
参照陈竞潇学长的模板写的BZOJ 3188: #include<cstdio> #include<cstring> #include<algorithm> #def ...
- BZOJ SCOI2005骑士精神
裸IDA*,ans从1到15循环来限制搜索深度. #include<cstdio> #include<cstring> #include<algorithm> us ...