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 ...
随机推荐
- java 中Handler 和Runnable 的使用 异步发送消息 转
public class MainActivity extends Activity { TextView text1, text2; Button button; Thread th; @Overr ...
- 人家为撩妹就鼓捣个网页,我做了个约炮APP(已开源)
每年初夏第一场雷雨刚过,漫步河边的草坪,总是能闻到伴随着泥土的清新,这不是coco的前香,让人神魂颠倒:也不是gucci的后香,让人痴迷如梦.如24节气一样,它提醒人们,夏天到了.昨晚成都下了第一场雷 ...
- 怎样写 OpenStack Neutron 的 Extension (四)
上文说到需要在 /neutronclient/v2_0/myextension/extension.py 中分别定义五个 class:List/Show/Create/Delete/UpdateExt ...
- Moqui学习Day3
添加一个新建表单 添加一个按钮来弹出新建表单,并创建一个转换来处理输入数据操作. 在FindTutorial.xml文件中添加一个转换. <!--新增 列表 --> <transit ...
- Oracle创建表格报ORA-00906:缺失左括号错误解决办法
来源于:http://www.linuxidc.com/Linux/2013-06/85297.htm 解决办法: create table myTable(id number(5,2),name v ...
- js实现开灯关灯效果
<!DOCTYPE html> <html> <body> <script> function changeImage() { element=docu ...
- Asp.Net MVC 中实现跨域访问
在ASP.Net webapi中可以使用 Microsoft.AspNet.WebApi.Cors 来实现: public static class WebApiConfig { public s ...
- Struts2(二)---将页面表单中的数据提交给Action
问题:在struts2框架下,如何将表单数据传递给业务控制器Action. struts2中,表单想Action传递参数的方式有两种,并且这两种传参方式都是struts2默认实现的,他们分别是基本属性 ...
- 用批处理文件来手动启动和停止Oracle服务
服务名称 说明 OracleOracle_homeTNSListener 对应于数据库的监听程序 OracleServiceSID 对应于数据库的例程 OracleDBConsoleSID ...
- 打印cell的视图层次结构
#ifdef DEBUG NSLog(@"Cell recursive description:\n\n%@\n\n", [cell performSelector:@select ...