poj 1125 谣言传播 Floyd 模板题
假如有3个点 点1到点2要5分钟 点1到点3要3分钟 那么5分钟的时间可以传遍全图 所以要先找一个点到其他点的最长时间 再从最长的时间里找出最小值
Sample Input
3 // 结点数
2 2 4 3 5 //点1与另外2个点相连 1->2 权值为4 1->3 权值为5
2 1 2 3 6 //点2与...
2 1 2 2 2//点3...
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
# include <iostream>
# include <cstdio>
# include <cstring>
# include <string>
# include <algorithm>
# include <cmath>
# include <map>
# define LL long long
using namespace std ; const int MAXN = ;
const int INF = 0x3f3f3f3f;
int dis[MAXN][MAXN];
int n ; void floyed()//节点从1~n编号
{
int i,j,k;
for(k=;k<=n;k++)
for(i=;i<=n;i++)
for(j=;j<=n;j++)
if(dis[i][k]+dis[k][j] < dis[i][j])
dis[i][j]=dis[i][k]+dis[k][j]; } int main()
{
//freopen("in.txt","r",stdin) ;
while (scanf("%d" , &n) , n)
{
int i , j ;
for(i=;i<=n;i++)
for(j=;j<=n;j++)
{
if(i==j)dis[i][j]=;
else dis[i][j]=INF;
}
int m ,v ,w ;
for(i=;i<=n;i++)
{
scanf("%d" , &m) ;
while(m--)
{
scanf("%d %d" , &v , &w) ;
if (w < dis[i][v])
dis[i][v] = w ;
}
}
floyed() ;
int ans = INF ;
int k ;
for(i=;i<=n;i++)
{
int t = ;
for(j=;j<=n;j++)
{
if (i != j && dis[i][j] > t)
{
t = dis[i][j] ;
}
}
if (t < ans)
{
ans = t ;
k = i ;
}
}
if (ans != INF)
printf("%d %d\n" , k , ans) ;
else
printf("disjoint\n") ;
}
return ;
}
poj 1125 谣言传播 Floyd 模板题的更多相关文章
- POJ 1502 MPI Maelstrom(模板题——Floyd算法)
题目: BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distri ...
- POJ 1287 Networking【kruskal模板题】
传送门:http://poj.org/problem?id=1287 题意:给出n个点 m条边 ,求最小生成树的权 思路:最小生树的模板题,直接跑一遍kruskal即可 代码: #include< ...
- POJ 1470 Closest Common Ancestors (模板题)(Tarjan离线)【LCA】
<题目链接> 题目大意:给你一棵树,然后进行q次询问,然后要你统计这q次询问中指定的两个节点最近公共祖先出现的次数. 解题分析:LCA模板题,下面用的是离线Tarjan来解决.并且为了代码 ...
- POJ 3264 Balanced Lineup(模板题)【RMQ】
<题目链接> 题目大意: 给定一段序列,进行q次询问,输出每次询问区间的最大值与最小值之差. 解题分析: RMQ模板题,用ST表求解,ST表用了倍增的原理. #include <cs ...
- POJ 1330 Nearest Common Ancestors (模板题)【LCA】
<题目链接> 题目大意: 给出一棵树,问任意两个点的最近公共祖先的编号. 解题分析:LCA模板题,下面用的是树上倍增求解. #include <iostream> #inclu ...
- POJ:Dungeon Master(三维bfs模板题)
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16748 Accepted: 6522 D ...
- POJ 3068 运送危险化学品 最小费用流 模板题
"Shortest" pair of paths Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1215 ...
- Poj 1125 Stockbroker Grapevine(Floyd算法求结点对的最短路径问题)
一.Description Stockbrokers are known to overreact to rumours. You have been contracted to develop a ...
- POJ:3461-Oulipo(KMP模板题)
原题传送:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS Memory Limit: 65536K Description The F ...
随机推荐
- SGU 271 Book Pile
There is a pile of N books on the table. Two types of operations are performed over this pile: - a b ...
- XML文件详解以及解析
转自:https://blog.csdn.net/com_ma/article/details/73277535 一.xml基础详解: 1.概述: xml:即可扩展标记语言,xml是互联网数据传输的重 ...
- android measure的时候报空指针
1.使用listview的时候,在代码中动态设置其高度,在android低版本中,这个低版本是以4.4为界,会报measure的空指针,原因是低版本relativelayout有个bug,使用list ...
- 自动部署tomcat,并以普通用户身份运行 for centos6
#!/bin/bash ######## install jdk install_jdk () { rpm -e ‘rpm -qa |grep jdk’ wget \ --no-check-certi ...
- Kafka0.10.0安装配置
1 解压文件 tar -zvxf kafka_2.11-0.10.0.0.tgz 2 修改配置server.properties vim server.properties broker.id=1 z ...
- java先导课程学习总结
经过两个星期四节课的java学习,我也对java这门语言有了一定的认识.刚开始上课的时候,我认为java把C语言中老师所说的模块化编程进行了强调,进行一个类,一个类的编程,在类中构造相应的方法,使用的 ...
- 在虚拟机安装windows xp时所需要的序列号
最新的windows xp sp3序列号 xp序列号 最新的windows xp sp3序列号(绝对可通过正版验证) MRX3F-47B9T-2487J-KWKMF-RPWBY(工行版) 可用(强推 ...
- sun.misc.BASE64Encoder等类报错的解决方法
一.引言: sun.misc.BASE64Encoder等类不属于JDK标准库范畴,但在JDK中包含了该类,可以直接使用.但是在eclipse中直接使用却报错.本文就介绍一下针对这样的类如何处理. 二 ...
- host-only
https://www.cnblogs.com/yaox/p/6635312.html
- 【逆向工具】IDA使用1-VS2015版本debug查找Main函数,加载符号文件
IDA 常见操作 空格,切换反汇编视图 选择CALL或是跳转 进入函数内部或是跳转处 返回键 ESC daq.exe 分析32位程序 ,生成的IDA数据库文件是 .idb Idap64.exe 分析6 ...