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 ...
随机推荐
- 遍历INI文件和删除指定域内容
主要还是使用的INI文件操作的API,只是把参数修改下. BOOL WINAPI WritePrivateProfileString( __in LPCTSTR lpAppName, __in LPC ...
- *candy——leetcode
/* */ #include<iostream> #include<vector> //#include<algorithm> #include <windo ...
- 【C++深入探索】Copy-and-swap idiom详解和实现安全自我赋值
分类: C/C++2012-08-30 21:40 2017人阅读 评论(2) 收藏 举报 任何管理某资源的类比如智能指针需要遵循一个规则(The Rule of Three): 如果你需要显式地声明 ...
- [转] Python 模块学习:os模块
一.os模块概述 Python os模块包含普遍的操作系统功能.如果你希望你的程序能够与平台无关的话,这个模块是尤为重要的.(一语中的) 二.常用方法 1.os.name 输出字符串指示正在使用的平台 ...
- Android(java)学习笔记250:ContentProvider使用之获得系统联系人信息02(掌握)
1.重要: 系统删除一个联系人,默认情况下并不是把这个联系人直接删除掉了,只是做了一个标记,标记为被删除. 2.前面一讲说过了如何获取系统联系人信息(通过ContentProvider),获取联系人信 ...
- LA 6448 Credit Card Payment
[题目] 你的信用卡目前欠M元,每月的汇率是R,每月的利息要四舍五入为小数点后两位,你每月还B元,问多少月能还清. 输入 先是T代表测试数据组数 接下来T行,每行有三个实数,R,M,B每个实数小数 ...
- Asp.Net WebAPI 中Cookie 获取操作方式
1. /// <summary> /// 获取上下文中的cookie /// </summary> /// <returns></returns> [H ...
- PHP语言中使用JSON
原文地址:http://www.ruanyifeng.com/blog/2011/01/json_in_php.html 在PHP语言中使用JSON 目前,JSON已经成为最流行的数据交换格式之一,各 ...
- ORACLE日期加减【转】
首先,感谢这个作者的辛勤汗水给我们带来的总结,因为日期函数操作对平时的使用真的是很常用,所以收藏一下以作后期使用. 原贴地址:http://www.cnblogs.com/xiao-yu/archiv ...
- aps.net 用ajax 读取服务端值
1.Default.aspx 页面内容 实例一: <%@ Page Language="C#" AutoEventWireup="true" Code ...