[USACO09OPEN]捉迷藏Hide and Seek
OJ题号:洛谷2951
思路:Dijkstra+堆优化。注意是无向图,所以加边时要正反各加一遍。
#include<cstdio>
#include<vector>
#include<ext/pb_ds/priority_queue.hpp>
#define dis first
#define to second
const int N=,inf=0x7fffffff;
typedef std::pair<int,int> Edge;
int n,m,d[N];
std::vector<int> e[N];
void add(int a,int b) {
e[a].push_back(b);
}
void dijkstra() {
__gnu_pbds::priority_queue<Edge,std::greater<Edge> > q;
__gnu_pbds::priority_queue<Edge,std::greater<Edge> >::point_iterator a[n+];
for(int i=;i<=n;i++) {
a[i]=q.push((i==)?(Edge){,i}:(Edge){inf,i});
d[i]=(i==)?:inf;
}
while(!q.empty()) {
Edge x=q.top();
q.pop();
if(x.dis==inf) continue;
int u=x.to;
for(std::vector<int>::iterator i=e[u].begin();i<e[u].end();i++) {
int& next=*i;
if(d[u]+<d[next]) {
d[next]=d[u]+;
q.modify(a[next],(Edge){d[next],next});
}
}
}
}
int main() {
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++) {
int a,b;
scanf("%d%d",&a,&b);
add(a,b);
add(b,a);
}
dijkstra();
int id,dis=,count=;
for(int i=;i<=n;i++) {
if(d[i]==dis) count++;
if(d[i]>dis) {
id=i;
dis=d[i];
count=;
}
}
printf("%d %d %d\n",id,dis,count);
return ;
}
[USACO09OPEN]捉迷藏Hide and Seek的更多相关文章
- 洛谷 P2951 [USACO09OPEN]捉迷藏Hide and Seek
题目戳 题目描述 Bessie is playing hide and seek (a game in which a number of players hide and a single play ...
- P2951 【[USACO09OPEN]捉迷藏Hide and Seek】
典型的最短路,而且只要再加一点点操作,就能得到答案 所以可以直接套模板 具体看程序:: #include<cstdio> #include<queue>//队列专属头文件 #i ...
- Luogu 2951 捉迷藏Hide and Seek
P2951 [USACO09OPEN]捉迷藏Hide and Seek 题目描述 Bessie is playing hide and seek (a game in which a number o ...
- USACO Hide and Seek
洛谷 P2951 [USACO09OPEN]捉迷藏Hide and Seek 洛谷传送门 JDOJ 2641: USACO 2009 Open Silver 1.Hide and Seek JDOJ传 ...
- BZOJ3402: [Usaco2009 Open]Hide and Seek 捉迷藏
3402: [Usaco2009 Open]Hide and Seek 捉迷藏 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 51 Solved: 4 ...
- BZOJ 3402: [Usaco2009 Open]Hide and Seek 捉迷藏
题目 3402: [Usaco2009 Open]Hide and Seek 捉迷藏 Time Limit: 3 Sec Memory Limit: 128 MB Description 贝 ...
- 3402: [Usaco2009 Open]Hide and Seek 捉迷藏
3402: [Usaco2009 Open]Hide and Seek 捉迷藏 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 78 Solved: 6 ...
- 【BZOJ-1941】Hide and Seek KD-Tree
1941: [Sdoi2010]Hide and Seek Time Limit: 16 Sec Memory Limit: 162 MBSubmit: 830 Solved: 455[Submi ...
- [BZOJ1941][Sdoi2010]Hide and Seek
[BZOJ1941][Sdoi2010]Hide and Seek 试题描述 小猪iPig在PKU刚上完了无聊的猪性代数课,天资聪慧的iPig被这门对他来说无比简单的课弄得非常寂寞,为了消除寂寞感,他 ...
随机推荐
- windows系统中hosts文件位置
C:\Windows\System32\drivers\etc\hosts 10.0.0.213 mr1.bic.zte.com 10.0.0.2 mr2.bic.zte.com 10.0.0.102 ...
- freeRTOS中文实用教程1--任务
1.前言 FreeRTOS是小型多任务嵌入式操作系统,硬实时性.本章主要讲述任务相关特性及调度相关的知识. 2. 任务的总体特点 任务的状态 (1)任务有两个状态,运行态和非运行态 (2)任务由非运行 ...
- python中的这些坑,早看早避免。
python中的这些坑,早看早避免. 说一说python中遇到的坑,躲坑看这一篇就够了 传递参数时候不要使用列表 def foo(num,age=[]): age.append(num) print( ...
- C++:__stdcall详解
原文地址:http://www.cnblogs.com/songfeixiang/p/3733661.html 对_stdcall 的理解(上)在C语言中,假设我们有这样的一个函数:int funct ...
- mysql锁表与不锁表设置主从复制的方法
有时候MySQL主从同步不一致比较严重的时候,需要手动同步.先说说在锁表的情况下如何操作:以下是其简要过程 1.先对主库锁表FLUSH TABLES WITH READ LOCK; 2.备份数据mys ...
- 使用python命令构建最简单的web服务
可以使用python自带的包建立最简单的web服务器,使用方法: 1)切换到服务器的根目录下 2)输入命令: python -m SimpleHTTPServer 3)使用wget或者在浏览器访问测试 ...
- Project Euler Problem8
Largest product in a series Problem 8 Find the greatest product of five consecutive digits in the 10 ...
- zabbix3.0.4报错Get value from agent failed: cannot connect to [[1.1.1.1]:10050]: [4] Interrupted syste
一.问题描述 部署完Zabbix agent之后,Server无法获取到数据.报错.报错信息如下: Get value from agent failed: cannot connect to [[1 ...
- 不同系统与程序修改java.library.path的位置(转)
原文地址:http://blog.csdn.net/quqibing001/article/details/51201768 Linux环境 系统变量LD_LIBRARY_PATH来添加Java.li ...
- Android中PopupWindow用法
参考资料链接:http://developer.android.com/reference/android/widget/PopupWindow.html 在Android中有很多级别的Window, ...