题目

3402: [Usaco2009 Open]Hide and Seek 捉迷藏

Time Limit: 3 Sec  Memory Limit: 128 MB

Description

    贝茜在和约翰玩一个“捉迷藏”的游戏.
    她正要找出所有适合她躲藏的安全牛棚.一共有N(2≤N≤20000)个牛棚,被编为1到N号.她知道约翰(捉牛者)从牛棚1出发.所有的牛棚由M(1≤M≤50000)条双向路连接,每条双向路连接两个不同的牛棚.所有的牛棚都是相通的.贝茜认为同牛棚1距离最远的的牛棚是安全的.两个牛棚间的距离是指,从一个牛棚到另一个牛棚最少需要通过的道路数量.请帮贝茜找出所有的安全牛棚.

Input

    第1行输入两个整数N和M,之后M行每行输入两个整数,表示一条路的两个端点.
   

Output

仅一行,输出三个整数.第1个表示安全牛棚(如果有多个,输出编号最小的);第2个表示牛棚1和安全牛棚的距离;第3个表示有多少个安全的牛棚.

Sample Input

6 7
3 6
4 3
3 2
1 3
1 2
2 4
5 2

Sample Output

4 2 3

HINT

 

Source

题解

呃,这一题嘛。。就是一个SPFA嘛!我数组开小了,怒献一次WA!

代码

 /*Author:WNJXYK*/
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std; int n,m; struct Edge{
int v;
int t;
int nxt;
Edge(){}
Edge(int a,int b,int c){
v=a;t=b;nxt=c;
}
};
Edge e[];
int nume;
int head[];
inline void addSingleEdge(int x,int y,int w){
e[++nume]=Edge(y,w,head[x]);
head[x]=nume;
}
inline void addEdge(int x,int y,int w){
addSingleEdge(x,y,w);
addSingleEdge(y,x,w);
} queue<int> que;
double dist[];
bool inque[]; inline void spfa(int src){
bool isPrint=false;
while(!que.empty()) que.pop();
memset(dist,,sizeof(dist));
memset(inque,false,sizeof(inque));
que.push(src);
dist[src]=;
inque[src]=true;
while(!que.empty()){
int now=que.front();
que.pop();
for (int i=head[now];i;i=e[i].nxt){
int v=e[i].v;int w=e[i].t;
if (dist[v]>dist[now]+w){
dist[v]=dist[now]+w;
if (!inque[v]){
inque[v]=true;
que.push(v);
}
}
}
}
} int main(){
scanf("%d%d",&n,&m);
for (int i=;i<=m;i++){
int x,y;
scanf("%d%d",&x,&y);
addEdge(x,y,);
}
spfa();
int maxDist=,minId=,maxNum=;
for (int i=;i<=n;i++){
if (maxDist<dist[i]){
maxDist=dist[i];
minId=i;
maxNum=;
}else if (maxDist==dist[i])maxNum++;
}
printf("%d %d %d\n",minId,maxDist,maxNum);
return ;
}

BZOJ 3402: [Usaco2009 Open]Hide and Seek 捉迷藏的更多相关文章

  1. BZOJ—— 3402: [Usaco2009 Open]Hide and Seek 捉迷藏

    http://www.lydsy.com/JudgeOnline/problem.php?id=3402 Description     贝茜在和约翰玩一个“捉迷藏”的游戏.     她正要找出所有适 ...

  2. BZOJ 3402: [Usaco2009 Open]Hide and Seek 捉迷藏(最短路)

    这个= =一看就是最短路了= = PS:最近有点懒 = = 刚才看到一道平衡树的裸题还嫌懒不去写= =算了等刷完这堆水题再去理= = CODE: #include<cstdio>#incl ...

  3. 3402: [Usaco2009 Open]Hide and Seek 捉迷藏

    3402: [Usaco2009 Open]Hide and Seek 捉迷藏 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 78  Solved: 6 ...

  4. 【BZOJ】3402: [Usaco2009 Open]Hide and Seek 捉迷藏(spfa)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3402 又是spfa水题.. #include <cstdio> #include < ...

  5. BZOJ3402: [Usaco2009 Open]Hide and Seek 捉迷藏

    3402: [Usaco2009 Open]Hide and Seek 捉迷藏 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 51  Solved: 4 ...

  6. B3402 [Usaco2009 Open]Hide and Seek 捉迷藏 最短路

    直接最短路板子,dij堆优化. 题干: 题目描述 贝茜在和约翰玩一个“捉迷藏”的游戏. 她正要找出所有适合她躲藏的安全牛棚.一共有N(≤N≤)个牛棚,被编为1到N号.她知道约翰(捉牛者)从牛棚1出发. ...

  7. 【BZOJ】【1941】【SDOI2010】Hide and Seek

    KD-Tree 一开始看错题了

  8. bzoj:1941: [Sdoi2010]Hide and Seek

    1941: [Sdoi2010]Hide and Seek Time Limit: 16 Sec  Memory Limit: 162 MBSubmit: 531  Solved: 295[Submi ...

  9. 洛谷 P2951 [USACO09OPEN]捉迷藏Hide and Seek

    题目戳 题目描述 Bessie is playing hide and seek (a game in which a number of players hide and a single play ...

随机推荐

  1. 【Android】创建Popwindow弹出菜单的两种方式

    方法一的Activity package com.app.test02; import android.app.Activity; import android.os.Bundle; import a ...

  2. 利用Console来调试JS程序、Console用法总结

    http://blog.163.com/zhangmihuo_2007/blog/static/27011075201452522824347/ http://blog.163.com/zhangmi ...

  3. Notes常用事件整理

    ①      ボタンのクリック事件: Sub Click(Source As Button) Dim ws As New NotesUIWorkspace Dim uidoc As NotesUIDo ...

  4. java中常用的数据加密算法

    以下为加密的工具类: import java.io.UnsupportedEncodingException; import java.security.InvalidKeyException; im ...

  5. Fedora 19下Guacamole的安装使用

    由于我要使用RDP实现web远程桌面,因此需要用到了Guacamole这个开源的软件.之前用Ubuntu12.04折腾了一晚上,也没有找到依赖库文件,而Guacamole的官方安装说明却没有介绍这个依 ...

  6. MacOS Apache配置

    仅适用于apache 2.2版本   查看版本 sudo apachectl -v   启动服务器 sudo apachectl start 打开localhost,可以看到内容为“It works! ...

  7. ETL工具之ODI

    ETL工具之ODI         到目前为止,Oracle的ETL工具包括两种,分别是Oracle Warehouse Builder(OWB)和Oracle Data Integrator(ODI ...

  8. Windows Server 2012 R2 Standard序列号

    备用一个吧,免得用起来的时候找不到. NB4WH-BBBYV-3MPPC-9RCMV-46XCB

  9. PullToRrefresh自定义下拉刷新动画

    首先,下载著名的刷新框架https://github.com/chrisbanes/Android-PullToRefresh,其中simple为demo,library和extras作为项目包导入到 ...

  10. MyBatis使用DEMO及cache的使用心得

    下面是一个简单的MyBatis使用DEMO. 整体结构 整体代码大致如下: POM依赖 需要引用两个jar包,一个是mybatis,另一个是mysql-connector-java,如果是maven工 ...