POJ1125 Stockbroker Grapevine 多源最短路
题目大意
给定一个图,问从某一个顶点出发,到其它顶点的最短路的最大距离最短的情况下,是从哪个顶点出发?须要多久?
(假设有人一直没有联络,输出disjoint)
解题思路
Floyd不解释
代码
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int INF = 1000000000;
const int maxn = 110;
int d[maxn][maxn];
int n;
int main()
{
//freopen("in.txt","r",stdin);
while(scanf("%d",&n) && n) {
for(int i = 0 ; i < maxn ; i ++) {
fill(d[i],d[i]+maxn,INF);
}
for(int i = 0 ; i < maxn ; i ++) d[i][i] = 0;
for(int i = 1 ; i <= n ; i ++) {
int t;
scanf("%d",&t);
while(t--) {
int a,b;
scanf("%d%d",&a,&b);
d[i][a] = b;
}
}
for(int k = 1 ; k <= n ; k ++) {
for(int i = 1 ; i <= n ; i ++) {
for(int j = 1 ; j <= n ; j ++) {
d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
}
}
}
int mi = INF;
int mark;
for(int i = 1 ; i <= n ; i ++) {
int ma = -1;
for(int j = 1 ; j <= n ; j ++) {
if(ma < d[i][j]) ma = d[i][j];
}
if(ma < mi) {
mi = ma;
mark = i;
}
}
if(mi < INF) {
printf("%d %d\n",mark,mi);
}else printf("disjoint\n");
}
return 0;
}
POJ1125 Stockbroker Grapevine 多源最短路的更多相关文章
- POJ1125 Stockbroker Grapevine(最短路)
题目链接. 分析: 手感不错,1A. 直接穷举的起点, 求出不同起点到其它点最短路中最长的一条的最小值(好绕). #include <iostream> #include <cstd ...
- POJ1125 Stockbroker Grapevine
Description Stockbrokers are known to overreact to rumours. You have been contracted to develop a me ...
- POJ1125 Stockbroker Grapevine(spfa枚举)
Description Stockbrokers are known to overreact to rumours. You have been contracted to develop a me ...
- poj1125 Stockbroker Grapevine Floyd
题目链接:http://poj.org/problem?id=1125 主要是读懂题意 然后就很简单了 floyd算法的应用 代码: #include<iostream> #include ...
- 最短路(Floyd_Warshall) POJ 1125 Stockbroker Grapevine
题目传送门 /* 最短路:Floyd模板题 主要是两点最短的距离和起始位置 http://blog.csdn.net/y990041769/article/details/37955253 */ #i ...
- Stockbroker Grapevine(最短路)
poj——1125 Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 36112 ...
- poj 1125 Stockbroker Grapevine(多源最短)
id=1125">链接:poj 1125 题意:输入n个经纪人,以及他们之间传播谣言所需的时间, 问从哪个人開始传播使得全部人知道所需时间最少.这个最少时间是多少 分析:由于谣言传播是 ...
- Stockbroker Grapevine(floyd+暴力枚举)
Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 31264 Accepted: 171 ...
- Stockbroker Grapevine(floyd)
Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 28231 Accepted: ...
随机推荐
- CodeForces 738A Interview with Oleg
模拟. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #includ ...
- 2010-2011 ACM-ICPC, NEERC, Southern Subregional Contest C Explode 'Em All
暴力枚举,状态压缩. 枚举哪几行放,复杂度为$O(2^{25})$,大概有$3000$多万种情况.假设有$x$行放了,没放的那几行状态或起来为$st$,如果$st$中$1$的个数大于$x$,那么不可取 ...
- UGUI的优点新UI系统四 开源
UGUI的优点新UI系统四 开源 新UI系统是开源的,所以开发者可以看到新UI系统实现的源码,并加以修改和使用. 开源授权协议——MIT/X11 Unity所搭载的新UI系统,是在开源授权协议MIT/ ...
- java 抽象方法 能用 静态 static 修饰,或者 native 修饰 么
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha static与abstract不能同时使用 用static声明方法表明这个方法在不生成类 ...
- luogu P1378 油滴扩展
题目描述 在一个长方形框子里,最多有N(0≤N≤6)个相异的点,在其中任何一个点上放一个很小的油滴,那么这个油滴会一直扩展,直到接触到其他油滴或者框子的边界.必须等一个油滴扩展完毕才能放置下一个油滴. ...
- [转]iBatis简单入门教程
iBatis 简介: iBatis 是apache 的一个开源项目,一个O/R Mapping 解决方案,iBatis 最大的特点就是小巧,上手很快.如果不需要太多复杂的功能,iBatis 是能够满足 ...
- C++ cout输出保留小数
参考: http://www.cnblogs.com/wushuaiyi/p/4439361.html http://blog.csdn.net/edricbjtu/article/details/4 ...
- iOS 11 安全区域适配
//解决iOS11,仅实现heightForHeaderInSection,没有实现viewForHeaderInSection方法时,section间距大的问题 [UITableView appea ...
- Jenkins用HTTP Request Plugin插件进行网站的监控/加探针(运维监控)
使用的插件: [HTTP Request Plugin] 思路: 说明:只能是网站是否正常打开,而不能是这个网站业务是否正常,如果是后者,则需要写特定的接口进行请求处理. 1.通过插件,发送GET请求 ...
- HDU 4417 Super Mario(划分树)
Super Mario Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...