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 ...
随机推荐
- [Angular 2] Child Router
Benefit to use child router is Angualr 2 then can lazy load the component on demand. Define a child ...
- unicode下各种类型转换,CString,string,char*,int,char[]
把最近用到的各种unicode下类型转换总结了一下,今后遇到其他的再补充: 1.string转CString string a=”abc”; CString str=CString(a.c_str() ...
- android开发之——混淆编译
众所周知,android的apk文件是非常容易被反编译的,这样对于开发者来说,辛辛苦苦开发应用被破解是一件很令人懊恼的事情,谷歌也认识到了这一点,所以从2.3之后就为开发者提供了一个代码混淆工具pro ...
- GraphViz web版
http://graphviz-dev.appspot.com/ 用来把dot语言的图画出来,很多地方用dot语言来画图,比如doxygen的类关系,gperftools的分析结果等.
- mui实现支付宝支付功能
<!DOCTYPE html><html> <head> <meta charset="utf-8"> <title>H ...
- SQL读取系统时间的语法(转)
--获取当前日期(如:yyyymmdd) select CONVERT (nvarchar(12),GETDATE(),112) --获取当前日期(如:yyyymmdd hh:MM:ss)select ...
- ASP.NET实现年月日三级联动(局部刷新)
直接上代码,不多说别的了 <asp:ScriptManager ID="ScriptManager1" runat="server"> </a ...
- MySql中的时间类型datetime,timestamp,date,year比较
MySQL日期类型.日期格式.存储空间.日期范围比较.日期类型 存储空间 日期格式 日期范围------------ --------- ...
- POP动画引擎中Layer与CALayer的一点区别
POP动画引擎是facebook提供的一个开源框架, 可以实现很多的动画效果, 这里就不一一介绍啦, 有兴趣的童鞋请移步: https://github.com/facebook/pop 下面简单的讲 ...
- mvvm框架正式名字确定
经过长时间的选名,今天终于把名字定下来了,ddrjs data drive render,其实框架的核心还是 数据驱动渲染,其实现在市面上的大部分mvvm框架如:angular.vue.avalon ...