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 题意 : 就是说想要在股票经纪人中传播谣言,先告诉一个人,然后让他传播给其他所有的经纪人,需要输出的是从谁开始传播需要的时间最短,输出这个 ...
随机推荐
- 【BZOJ 3238】 3238: [Ahoi2013]差异(SAM)
3238: [Ahoi2013]差异 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 3047 Solved: 1375 Description In ...
- mui实现列表的下拉刷新上拉加载
1.引入mui控件的js文件和css样式文件 <link rel="stylesheet" href="css/mui.min.css"> < ...
- 字符串的模板 Manacher kmp ac自动机 后缀数组 后缀自动机
为何scanf("%s", str)不需要&运算 经常忘掉的字符串知识点,最好不加&,不加&最标准,指针如果像scanf里一样加&是错的,大概是未定 ...
- 背包的第k优解[动态规划]
From easthong ☆背包的第k优解 描述 Description DD 和好朋友们要去爬山啦!他们一共有 K 个人,每个人都会背一个包.这些包的容量是 ...
- 【最小点覆盖】POJ3041-Asteroids
[题目大意] 在n*n的网格上有n个点,每次删除一行或者一列,问至少要删除几次才能删除完全部的这些店? [思路] 在国庆最后一天到来前,把二分图的三个基本情况[最小点覆盖][DAG图的最小路径覆盖]和 ...
- 使用hadoop实现关联商品统计
转载请注明出处:http://blog.csdn.net/xiaojimanman/article/details/40184581 近期几天一直在看hadoop相关的书籍,眼下略微有点感觉,自己就仿 ...
- Windows上安装Git替代cmd命令行程序
git是一个版本管理系统,利用好它,可以管理你项目文件,每个文件的更新删除修改,它都知道,还可以还原回历史的某个版本. msysgit是Windows版的Git. 1.下载地址:https://git ...
- 第一章 Actionscript学习基本知识笔记及flashdevelop软件的安装问题
OOP:封装.继承.多态. Pubilc :完全公开. Internal:包内类成员可以互相访问. Private:仅当前类可以访问. Protected:当前类和当前类的子类可以访问. 被关键词fi ...
- 如何设置Win7不待机 Win7进入待机状态会断网的解决方法
电脑一旦进入待机状态后,会断网,应用将停止运行,因此需要设置电脑不待机来解决,这种情况需要挂一些游戏或者下载应用的时非常实用,下面就与大家分享下电脑不待机的设置方法,感兴趣的朋友可以参考下 有时候我们 ...
- 使用WebView出现web page not available
很有可能是没有设置权限,所以不能浏览相应的URL,设置如下: 在AndroidManifest.xml中添加 <uses-permission android:name="androi ...