BZOJ3402: [Usaco2009 Open]Hide and Seek 捉迷藏
3402: [Usaco2009 Open]Hide and Seek 捉迷藏
Time Limit: 3 Sec Memory Limit: 128 MB
Submit: 51 Solved: 40
[Submit][Status]
Description
Input
Output
仅一行,输出三个整数.第1个表示安全牛棚(如果有多个,输出编号最小的);第2个表示牛棚1和安全牛棚的距离;第3个表示有多少个安全的牛棚.
Sample Input
3 6
4 3
3 2
1 3
1 2
2 4
5 2
Sample Output
HINT
Source
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 100000
#define maxm 100000
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define mod 1000000007
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
struct edge{int go,next,w;}e[*maxm];
int n,m,mx,ans,tot,q[maxn],d[maxn],head[maxn];
bool v[maxn];
void insert(int x,int y)
{
e[++tot].go=y;e[tot].next=head[x];head[x]=tot;
e[++tot].go=x;e[tot].next=head[y];head[y]=tot;
}
void spfa()
{
for(int i=;i<=n;++i) d[i]=inf;
memset(v,,sizeof(v));
int l=,r=,x,y;q[]=;d[]=;
while(l!=r)
{
x=q[++l];if(l==maxn-)l=;v[x]=;
for(int i=head[x];i;i=e[i].next)
if(d[x]+<d[y=e[i].go])
{
d[y]=d[x]+;
if(!v[y]){v[y]=;q[++r]=y;if(r==maxn-)r=;}
}
}
}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();m=read();
for1(i,m)insert(read(),read());
spfa();
for2(i,,n)if(d[i]>d[mx])mx=i,ans=;else if(d[i]==d[mx])ans++;
printf("%d %d %d\n",mx,d[mx],ans);
return ;
}
BZOJ3402: [Usaco2009 Open]Hide and Seek 捉迷藏的更多相关文章
- 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】3402: [Usaco2009 Open]Hide and Seek 捉迷藏(spfa)
http://www.lydsy.com/JudgeOnline/problem.php?id=3402 又是spfa水题.. #include <cstdio> #include < ...
- BZOJ—— 3402: [Usaco2009 Open]Hide and Seek 捉迷藏
http://www.lydsy.com/JudgeOnline/problem.php?id=3402 Description 贝茜在和约翰玩一个“捉迷藏”的游戏. 她正要找出所有适 ...
- B3402 [Usaco2009 Open]Hide and Seek 捉迷藏 最短路
直接最短路板子,dij堆优化. 题干: 题目描述 贝茜在和约翰玩一个“捉迷藏”的游戏. 她正要找出所有适合她躲藏的安全牛棚.一共有N(≤N≤)个牛棚,被编为1到N号.她知道约翰(捉牛者)从牛棚1出发. ...
- BZOJ 3402: [Usaco2009 Open]Hide and Seek 捉迷藏(最短路)
这个= =一看就是最短路了= = PS:最近有点懒 = = 刚才看到一道平衡树的裸题还嫌懒不去写= =算了等刷完这堆水题再去理= = CODE: #include<cstdio>#incl ...
- 洛谷 P2951 [USACO09OPEN]捉迷藏Hide and Seek
题目戳 题目描述 Bessie is playing hide and seek (a game in which a number of players hide and a single play ...
- Luogu 2951 捉迷藏Hide and Seek
P2951 [USACO09OPEN]捉迷藏Hide and Seek 题目描述 Bessie is playing hide and seek (a game in which a number o ...
- 【BZOJ-1941】Hide and Seek KD-Tree
1941: [Sdoi2010]Hide and Seek Time Limit: 16 Sec Memory Limit: 162 MBSubmit: 830 Solved: 455[Submi ...
随机推荐
- atol字符串转换函数应用实例
原型:long atol(const char *nptr); 相关函数 atoi,atol,strtod,strtol,strtoul 头文件:stdlib.h 功能:将字符串转换成整型数 说明:参 ...
- EMV/PBOC解析(三) TLV格式解析(C#)
1.什么是TLV格式? TLV即Tag-Length-Value,常在IC卡与POS终端设备中通过这样的一个应用通信协议进行数据交换. 金融系统中的TLV是BER-TLV编码的一个特例编码规范,而BE ...
- RMAN-00554: initialization of internal recovery manager package failed RMAN-04005
[oracle@rac11g1 ~]$ rman target haha/haha@rac11g Recovery Manager: Release 11.2.0.3.0 - Production o ...
- 桌面环境与桌面搜索Desktop Search tools
最近一段时间工作重心都将放在Linux下Desktop search(桌面搜索)框架的研发上.因此对desktop search进行了初步的调研.本文将从下面三个方面展开: Linux桌面环境(Des ...
- Neutron中的Service类
Service是OpenStack中非常重要的一个概念,各个服务的组件都以Service类的方式来进行交互. Neutron中的Service类继承自rpc中的Service,总体的继承关系为 neu ...
- MySQL高可用基础之keepalived+双主复制【转】
环境:MySQL-VIP:192.168.1.3MySQL-master1:192.168.1.1MySQL-master2:192.168.1.2 OS版本:CentOS release 6.4 ( ...
- 使用单例模式实现自己的HttpClient工具类
引子 在Android开发中我们经常会用到网络连接功能与服务器进行数据的交互,为此Android的SDK提供了Apache的HttpClient 来方便我们使用各种Http服务.你可以把HttpCli ...
- Thinkpad Edge E440 Ubuntu14.04 无线网卡驱动 解决
http://ubuntuforums.org/showthread.php?t=2190347 正文: Thinkpad Edge E440 安装 Ubuntu12.04 后 无法使用无线网卡, 须 ...
- Array.asList:数组转list时你一定要知道的“陷阱”!
最近开发中,业务上处理,经常用到asList方法,这让我不经想起了它的很多容易让人犯错的地方或者误解的地方,所以就想抽出时间来,整理一下,和大家分享出来,深夜了,话不多说,主要以代码为主,简易的代码, ...
- 单向链表JAVA代码
//单向链表类 publicclassLinkList{ //结点类 publicclassNode{ publicObject data; ...