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 ...
随机推荐
- jq版轮播图
html部分 <div class="banner"> <ul class="img"> <li><img src=& ...
- Linux 4.10.8 根文件系统制作(二)---制作jiffs文件系统
一.制作jiffs文件系统 制作jffs2 文件系统需要用到 mkfs.jffs2工具. 执行命令: mkfs.jffs2 -n -s 0x800 -e 0x20000 --pad=0x800000 ...
- C++函数返回局部变量
函数不能返回指向栈内存的指针 原因:返回值是拷贝值,局部变量的作用域为函数内部,函数执行结束,栈上的局部变量会销毁,内存释放. 可返回的局部变量: 1. 返回局部变量本身 int sum(int a, ...
- VS中修改工程名的解决方案
VS中修改工程名的解决方案: 一.先修改工程名/解决方案名(在VS中修改即可)举例,原先的工程名为OldProject 想要改成NewProject1.找到工程/解决方案所在的文件夹(已工程名/解 ...
- VSS2005源代码管理
VSS2005使用详细 http://www.docin.com/p-467455948.html 花了差不多一天的时间把vss配置搞明白了~废话不多说,下面简单的介绍下配置的过程:安装VSS2005 ...
- 【通信】Jave代码中生成url http请求
/** * 向指定 URL 发送POST方法的请求 * * @param url * 发送请求的 URL * @param param * 请求参数,请求参数应该是 name1=value1& ...
- layer弹出层的iframe页面回调
$("#ChoiceBank").click(function () { var width = $("#content").css("Width&q ...
- 2018-2019-2 网络对抗技术 20165227 Exp2 后门原理与实践
2018-2019-2 网络对抗技术 20165227 Exp2 后门原理与实践 (1)例举你能想到的一个后门进入到你系统中的可能方式? 接收邮件的方式 (2)例举你知道的后门如何启动起来(win及l ...
- Docker安装ActiveMQ
⒈下载 docker pull webcenter/activemq ⒉运行 docker run -d --name myactivemq -p 8161:8161 -p 61613:61613 - ...
- Sql Server 2008 数据库18456错误怎么解决?
可以windows连接,以前都可以,昨天突然就不可以用SQL连接,报18456错误. 1.以windows验证模式进入数据库管理器. 2.右击sa,选择属性: 在常规选项卡中,重新填写密码和确认密码( ...