这个= =一看就是最短路了= =

PS:最近有点懒 = = 刚才看到一道平衡树的裸题还嫌懒不去写= =算了等刷完这堆水题再去理= =

CODE:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
#define maxm 100010
#define maxn 20020
struct edges{
 int to,next;
}edge[maxm];
int next[maxn],l;
int addedge(int x,int y){
 edge[++l]=(edges){y,next[x]};next[x]=l;
 edge[++l]=(edges){x,next[y]};next[y]=l;
 return 0;
}
int dist[maxn],n,m;
bool b[maxn];
queue<int>q;
#define inf 0x7fffffff
int spfa(){
 for (int i=1;i<=n;i++) dist[i]=inf;
 dist[1]=0;
 q.push(1);
 while (!q.empty()){
  int u=q.front();q.pop();
  b[u]=0;
  for (int i=next[u];i;i=edge[i].next)
   if (dist[edge[i].to]>dist[u]+1){
    dist[edge[i].to]=dist[u]+1;
    if (!b[edge[i].to]) {
     q.push(edge[i].to);
     b[edge[i].to]=1;
    }
   }
 }
}
int main(){
 scanf("%d%d",&n,&m);
 for (int i=1;i<=m;i++) {
  int x,y;
  scanf("%d%d",&x,&y);
  addedge(x,y);
 }
 spfa();
 int ans=0,sum=0;
 for (int i=2;i<=n;i++) {
  if (dist[i]>dist[ans]) ans=i,sum=0;
  if (dist[i]==dist[ans]) sum++;
 }
 printf("%d %d %d",ans,dist[ans],sum);
 return 0;
}

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

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

    题目 3402: [Usaco2009 Open]Hide and Seek 捉迷藏 Time Limit: 3 Sec  Memory Limit: 128 MB Description     贝 ...

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

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

  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. B3402 [Usaco2009 Open]Hide and Seek 捉迷藏 最短路

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

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

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

  7. BZOJ 1579: [Usaco2009 Feb]Revamping Trails 道路升级( 最短路 )

    最短路...多加一维表示更新了多少条路 -------------------------------------------------------------------------------- ...

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

    KD-Tree 一开始看错题了

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

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

随机推荐

  1. 使用SSH搭建用户注册登录系统

    [转]http://blog.sina.com.cn/s/blog_a6a6b3cd01017c57.html 什么是SSH? SSH对应 struts spring hibernatestruts ...

  2. Python科学计算之Pandas

    Reference: http://mp.weixin.qq.com/s?src=3&timestamp=1474979163&ver=1&signature=wnZn1UtW ...

  3. Django之强大的Form功能

    转载: http://www.cnblogs.com/0820-zq/p/5807980.html Form Form的验证思路 前端:form表单 后台:创建form类,当请求到来时,先匹配,匹配出 ...

  4. EclipseEE导入项目出现的那些问题

    1.显示.project文件丢失, 解决方法:在eclipse中删除和该项目相同的文件名,重新import即可 2.导入没有.classpath和.project文件的项目 解决方法:目前没遇到 3. ...

  5. linux环境下Vim的配置

    原文链接:http://blog.chinaunix.net/uid-26826958-id-3272375.html  (本文转自此链接中的部分内容,但做了适当修改) 安装vim命令:sudo ap ...

  6. php AES 加密类

    <?php class CryptAES { protected $cipher = MCRYPT_RIJNDAEL_128; protected $mode = MCRYPT_MODE_ECB ...

  7. 利用 Grunt (几乎)无痛地做前端开发 (一)之单元测试

    前言 如果你想开发一个js应用,甭管多简单,都要先创建整个宇宙 来看看我们的Javascript小宇宙: 确定如何根据需求.功能划分模块,如何将代码分成多个文件开发,合成一个发布 保证上一条的同时,使 ...

  8. VirtualBox中安装Android-x86详解

    1.下载安装VirtualBox 官网:http://www.virtualbox.org/wiki/Downloads 2.下载Android-x86 官网:http://www.android-x ...

  9. 解析 png 图片的十六进制字符流

    uses pngimage; {从 png 图片到十六进制字符串} function Png2Hex(png: TPngImage): string; var stream: TMemoryStrea ...

  10. Goldengate双向复制配置

    一.Goldengate双向复制配置 1.1.在进行如下配置之前,先在源数据库source system(原来的目标数据库)端 添加辅助的redolog配置: SQL>alter databas ...