poj 1125 (floyed 最短路径)
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 26395 | Accepted: 14558 |
Description
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.
Input
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.
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<iostream>
using namespace std;
int main(){
int G[105][105];
int n,m;
while(cin>>n&&n){
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(i==j)
G[i][j]=0;
else
G[i][j]=999999;
for(int i=1;i<=n;i++){
cin>>m;
for(int j=1;j<=m;j++){
int v,t; cin>>v>>t;
G[i][v]=t;
}
}
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
// for(int k=1;k<=n;k++) k要放在前面,放这里会wrong answer
G[i][j]= G[i][j] > G[i][k]+G[k][j] ? G[i][k]+G[k][j] : G[i][j]; int v,t;
t=999999;
v=0;
for(int i=1;i<=n;i++){
int max; max=0;
for(int j=1;j<=n;j++){
if(G[i][j]>max)
max=G[i][j];
}
if(max>=999999)
continue;
if(t>max){
t=max;
v=i;
}
}
if(v==0)
cout<<"disjoint"<<endl;
else
cout<<v<<' '<<t<<endl;
}
return 0;
}
poj 1125 (floyed 最短路径)的更多相关文章
- 最短路(Floyd_Warshall) POJ 1125 Stockbroker Grapevine
题目传送门 /* 最短路:Floyd模板题 主要是两点最短的距离和起始位置 http://blog.csdn.net/y990041769/article/details/37955253 */ #i ...
- 【POJ 1125】Stockbroker Grapevine
id=1125">[POJ 1125]Stockbroker Grapevine 最短路 只是这题数据非常水. . 主要想大牛们试试南阳OJ同题 链接例如以下: http://acm. ...
- poj 1125 Stockbroker Grapevine(多源最短)
id=1125">链接:poj 1125 题意:输入n个经纪人,以及他们之间传播谣言所需的时间, 问从哪个人開始传播使得全部人知道所需时间最少.这个最少时间是多少 分析:由于谣言传播是 ...
- Poj 1125 Stockbroker Grapevine(Floyd算法求结点对的最短路径问题)
一.Description Stockbrokers are known to overreact to rumours. You have been contracted to develop a ...
- poj 1125 Stockbroker Grapevine dijkstra算法实现最短路径
点击打开链接 Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 23760 Ac ...
- poj 1125 Stockbroker Grapevine(最短路径)
Description Stockbrokers are known to overreact to rumours. You have been contracted to develop a me ...
- poj 1125 (floyd)
http://poj.org/problem?id=1125. 题意:在经纪人的圈子里,他们各自都有自己的消息来源,并且也只相信自己的消息来源,他们之间的信息传输也需要一定的时间.现在有一个消息需要传 ...
- 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 题意 : 就是说想要在股票经纪人中传播谣言,先告诉一个人,然后让他传播给其他所有的经纪人,需要输出的是从谁开始传播需要的时间最短,输出这个 ...
随机推荐
- cocos2d-android 使用 cocos2d 绘图
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha cocos2d-android-1 https://github.com/ZhouWei ...
- ZOJ 3707 Calculate Prime S 数论
思路:容易得到s[n]=s[n-1]+s[n-2],也就是fib数. 求第k小的fib质数的也就是第k个质数数-2,当k>2时. 在就是s[n]/x%m=s[n]%(x*m)/x. 代码如下: ...
- ArrayList源码阅读----JDK1.8
//定义一个默认的长度10 private static final int DEFAULT_CAPACITY = 10; //定义空的数组 private static final Object[] ...
- c# -- 解决FromsAuthentication上下文不存在
使用 FormsAuthentication.HashPasswordForStoringInConfigFile("需要加密的字符串", "MD5")这个方法 ...
- Codeforces Beta Round #8 B. Obsession with Robots 暴力
B. Obsession with Robots 题目连接: http://www.codeforces.com/contest/8/problem/B Description The whole w ...
- Qt on android 蓝牙开发(控制小车)
因为要做一个用蓝牙控制小车的app,就用着QT搞了下,网上关于QT蓝牙开发的资料比较少,我在这里记录下过程希望对看到了人有所帮助 首先在项目文件里添加 QT += bluetooth 这样就可以用QT ...
- Debounce 和 Throttle 的原理及实现---防止频繁触发某事件
原文:http://blog.csdn.net/redtopic/article/details/69396722 在处理诸如 resize.scroll.mousemove 和 keydown/ke ...
- JavaScript Diagramming
JavaScript Diagramming Optensity
- iOS程序的启动图片图标规范
- switch语句的基本使用
switch是一个多分支的选择语句. 1.基本格式: switch(整型表达式){ case 整型字面量: ...... default : } 解释: 1)整型字面量可 ...