题目大意

给定一个图,问从某一个顶点出发,到其它顶点的最短路的最大距离最短的情况下,是从哪个顶点出发?须要多久?

(假设有人一直没有联络,输出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 多源最短路的更多相关文章

  1. POJ1125 Stockbroker Grapevine(最短路)

    题目链接. 分析: 手感不错,1A. 直接穷举的起点, 求出不同起点到其它点最短路中最长的一条的最小值(好绕). #include <iostream> #include <cstd ...

  2. POJ1125 Stockbroker Grapevine

    Description Stockbrokers are known to overreact to rumours. You have been contracted to develop a me ...

  3. POJ1125 Stockbroker Grapevine(spfa枚举)

    Description Stockbrokers are known to overreact to rumours. You have been contracted to develop a me ...

  4. poj1125 Stockbroker Grapevine Floyd

    题目链接:http://poj.org/problem?id=1125 主要是读懂题意 然后就很简单了 floyd算法的应用 代码: #include<iostream> #include ...

  5. 最短路(Floyd_Warshall) POJ 1125 Stockbroker Grapevine

    题目传送门 /* 最短路:Floyd模板题 主要是两点最短的距离和起始位置 http://blog.csdn.net/y990041769/article/details/37955253 */ #i ...

  6. Stockbroker Grapevine(最短路)

      poj——1125 Stockbroker Grapevine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 36112 ...

  7. poj 1125 Stockbroker Grapevine(多源最短)

    id=1125">链接:poj 1125 题意:输入n个经纪人,以及他们之间传播谣言所需的时间, 问从哪个人開始传播使得全部人知道所需时间最少.这个最少时间是多少 分析:由于谣言传播是 ...

  8. Stockbroker Grapevine(floyd+暴力枚举)

    Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 31264 Accepted: 171 ...

  9. Stockbroker Grapevine(floyd)

    Stockbroker Grapevine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28231   Accepted: ...

随机推荐

  1. 关于matplotlib,你要的饼图在这里

    Table of Contents 1  官方Demo 2  将实际数据应用于官方Demo 3  一些改善措施 3.1  重新设置字体大小 3.2  设置显示颜色,Method 1: 3.3  设置显 ...

  2. 【剑指offer】9、斐波拉契数列

    面试题9.斐波拉契数列 题目: 输入整数n,求斐波拉契数列第n个数. 思路: 一.递归式算法: 利用f(n) = f(n-1) + f(n-2)的特性来进行递归,代码如下: 代码: long long ...

  3. Now Task

    1. Java 多线程 首先整理基本功,如线程的状态,和调度 多线程的经典例子,包括代码在内 多线程死锁的问题,要结合数据库的例子来整理 JDK1.5的若干要点 多线程的设计模式 2. NIO 需要掌 ...

  4. [BZOJ5250][九省联考2018]秘密袭击(DP)

    5250: [2018多省省队联测]秘密袭击 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 3  Solved: 0[Submit][Status][D ...

  5. hdu 1864 最大报销额(背包)

    最大报销额 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  6. 【数论】【二次剩余】【map】hdu6128 Inverse of sum

    部分引用自:http://blog.csdn.net/v5zsq/article/details/77255048 所以假设方程 x^2+x+1=0 在模p意义下的解为d,则答案就是满足(ai/aj) ...

  7. 【动态规划】【单调队列】tyvj1305 最大子序和

    http://blog.csdn.net/oiljt12138/article/details/51174560 单调队列优化dp #include<cstdio> #include< ...

  8. [HDU3756]Dome of Circus

    题目大意: 在一个立体的空间内有n个点(x,y,z),满足z>=0. 现在要你放一个体积尽量小的圆锥,把这些点都包住. 求圆锥的高和底面半径. 思路: 因为圆锥里面是对称的,因此问题很容易可以转 ...

  9. 安装Xampp-配置appche,mysql运行环境遇到的坑

    用php编写的web应用程序,需运行在php的web容器中,其中apache server是一个针对php web容器,它是apache下的开源项目.通常要运行一个web程序,我们还需要安装数据库软件 ...

  10. 迁移11g Rac中OCR和VOTEDISK

    环境:OEL+oracle rac 11.2.0.3 迁移描述:将ocr和votedisk从+DATE上迁移到+OCR_VOTE上: 操作如下: [root@ora2 ~]$ /u01/app/11. ...