题目大意:

输入n 接下来n行

每行输入m 接下来m对a,b

若干个人之间会传播谣言,但每个人传播给其他人的速度都不一样,

问最快的传播路线(即耗时最短的)中最耗时的一个传播环节。

如果其中有人不在这个链中,则输出disjoin,否则输出最快的传播人和该条传播路线中的最慢的一个传播环节花费时间。

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

3
2 2 4 3 5
2 1 2 3 6
2 1 2 2 2

三个点 两对值(点1) 到点2用时4 到点3用时5
两对值(点2) 到点1用时2 到点3用时6
两对值(点3) 到点1用时2 到点2用时2

3 2

从点3出发用时最短 其中最长用时为2
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
int G[][];
int main()
{
int n;
while(~scanf("%d",&n)&&n)
{
memset(G,INF,sizeof(G));
for(int i=;i<=n;i++)
{
G[i][i]=;
int m; scanf("%d",&m);
while(m--)
{
int a,b; scanf("%d%d",&a,&b);
G[i][a]=min(G[i][a],b);
}
} for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
for(int k=;k<=n;k++)
{
if(k==i||k==j||i==j) continue;
G[j][k]=min(G[j][k],G[j][i]+G[i][k]);
} /// Floyd求最短路 int minG=INF,maxG,index;
for(int i=;i<=n;i++)
{
maxG=;
for(int j=;j<=n;j++)
maxG=max(maxG,G[i][j]);
/// 从i出发的最长用时 若为INF 说明该条有缺口 if(minG>maxG) /// 得到最长用时中最短的一个
{
minG=maxG;
index=i;
}
} if(minG==INF) /// 说明整链有缺口
printf("disjoint\n");
else
printf("%d %d\n",index,minG);
} return ;
}

Southern African 2001 Stockbroker Grapevine /// Floyd oj1345的更多相关文章

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

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

  2. Stockbroker Grapevine(floyd)

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

  3. Poj 1125 Stockbroker Grapevine(Floyd算法求结点对的最短路径问题)

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

  4. poj1125 Stockbroker Grapevine Floyd

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

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

    Floyd算法计算每对顶点之间的最短路径的问题 题目中隐含了一个条件是一个人能够同一时候将谣言传递给多个人 题目终于的要求是时间最短.那么就要遍历一遍求出每一个点作为源点时,最长的最短路径长是多少,再 ...

  6. Southern African 2001 框架折叠 (拓扑序列的应用)

    本文链接:http://www.cnblogs.com/Ash-ly/p/5398377.html 题目:考虑五个图片堆叠在一起,比如下面的9 * 8 的矩阵表示的是这些图片的边缘框. 现在上面的图片 ...

  7. Stockbroker Grapevine POJ 1125 Floyd

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

  8. POJ 1125 Stockbroker Grapevine【floyd简单应用】

    链接: http://poj.org/problem?id=1125 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...

  9. OpenJudge/Poj 1125 Stockbroker Grapevine

    1.链接地址: http://poj.org/problem?id=1125 http://bailian.openjudge.cn/practice/1125 2.题目: Stockbroker G ...

随机推荐

  1. 树莓派 omv 安装 nextcloud

    https://www.toutiao.com/i6447470450145493517/ https://www.technikaffe.de/anleitung-402-howto_nextclo ...

  2. PXE装机

    支持 centOS 6 支持 PXE 装机的网卡必须自带 ROM(非意识性存储器)存储内容包括:DHCP 客户端,TFTP 客户端,PXE 协议客户端,将网卡设置第一启动项. DHCP:自动分配 IP ...

  3. gary's mod

    第一题: class Parent(object): x = 1 class Child1(Parent): pass class Child2(Parent): pass print(Parent. ...

  4. B-彻底删除卸载Ubuntu中的MySQL并重新安装(已验证)

    Ubuntu-16.04,MySQL-5.7,寻找多篇有关如何彻底卸载删除MySQL的博文, 最终验证下面转发博文真实有效,推荐! https://www.jianshu.com/p/c76b31df ...

  5. mac 常使用的一些小技巧

    全选 command +A 剪切 command + x 复制 ommand + c 粘贴 command + v 撤销 command + z 聚焦搜索 command + 空格 退出全屏窗口 Co ...

  6. 21-6-数组相关api

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. JS对象 编程练习 某班的成绩出来了,现在老师要把班级的成绩打印出来。 效果图: XXXX年XX月X日 星期X--班级总分为:81

    编程练习 某班的成绩出来了,现在老师要把班级的成绩打印出来. 效果图: XXXX年XX月X日 星期X--班级总分为:81 格式要求: 1.显示打印的日期. 格式为类似"XXXX年XX月XX日 ...

  8. 安装php 在阿里云yum源的环境

    yum -y install httpd mysql mysql-server php php-mysql postgresql postgresql-server php-postgresql ph ...

  9. 2.Struts2配置文件

    1.配置文件的加载顺序 0. 需要掌握         * 加载了哪些个配置文件(重点的)         * 配置文件的名称是什么         * 配置文件的位置         * 配置文件的 ...

  10. leetcode-回溯

    题17: 方法一:回溯 class Solution: def letterCombinations(self, digits: str) -> List[str]: res = [] dic ...