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 ...
随机推荐
- PL/SQL可以连oracle,但是jdbc连不上 【转】
场景描述 此处是jdbc连接: try { Class.forName("oracle.jdbc.driver.OracleDriver"); String url = " ...
- CentOS6.x下yum安装MySQL5.5/5.6
1. 安装mysql-5.5的yum源 # rpm -ivh http://repo.mysql.com/yum/mysql-5.5-community/el/6/x86_64/mysql-commu ...
- docker部署安装
docker采用Linux内核技术,所以只能运行在Linux上,所谓的windows平台是使用boot2Docker工具,boot2Docker是在VisualBox构建一个linux精简化环境. B ...
- Java中 break continue return 的区别
1.break break :跳出当前循环:但是如果是嵌套循环,则只能跳出当前的这一层循环,只有逐层break才能跳出所有循环: ; i < ; i++) { ) { break; // 在执行 ...
- Host is not allowed to connect to this MySQL server解决方法
在装有MySQL的机器上登录MySQL mysql -u root -p密码 执行use mysql; 执行update user set host = '%' where user = 'root' ...
- python的安装和pycharm的安装
下载地址 官网:https://www.python.org/downloads/release/python-372/ Window 平台安装 Python: Add python xx to ...
- 整数数字调节框QSpinBox
样式: import sys from PyQt5.QtWidgets import QApplication, QWidget, QSpinBox, QDoubleSpinBox, QHBoxLay ...
- gtid_executed和gtid_purged变量是如何初始化的
一.官方释义 1.1.gtid_executed.gtid_purged https://dev.mysql.com/doc/refman/5.7/en/replication-options-gti ...
- CentOS 6.8 部署django项目一
CentOS 6.8 部署django项目二 1.安装python3.5(默认是2.6) 参考:http://blog.csdn.net/shaobingj126/article/details/50 ...
- RabbitMQ运行机制
AMQP中消息的路由过程和Java开发者熟悉的JMS存在一些差别,AMQP中增加了Exchange和Binding的角色,生产者把消息发布到Exchange上,Binding决定发布到Exchange ...