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

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. javap -s 查看java方法签名

    工程先用eclipse生成class目录,转到class目录下执行: javap -s com.example.hellojni.MainActivity Compiled from "Ma ...

  2. iOS 设置UILable字体,及计算长度和位置

    UILabel *lastLable = [[UILabel alloc] init]; UIFont *font = [UIFont fontWithName:lastLable.font.font ...

  3. Scrum

    Scrum[编辑] 维基百科,自由的百科全书   Scrum是一种敏捷软件开发的方法学,用于迭代式增量软件开发过程.Scrum在英语是橄榄球运动中争球的意思. 虽然Scrum是为管理软件开发项目而开发 ...

  4. 关于js中for in的缺陷浅析

    关于js中for in的缺陷浅析 http://www.jb51.net/article/44028.htm

  5. 持续集成的一些讨论(CI)

    如何保证程序开发的新功能降低BUG,那就是需要他们自己写用测试工具来写测试用例,包括Mocha(JS).Junit(Java).GTest(C++):而上传到SVN或者GIT后,又如何保证能跟原有的功 ...

  6. 让Flash支持Stage3D

    如要需要支持Stage3D,采用GPU来渲染,需要设置wmode="direct",在FB中,对于web和air设置方法不同: 1.web: 需要在web的html模板中,添加参数 ...

  7. 递归编译的Makefile的实现

    最近写了一个递归Makefile,目的是既可以实现子模块的单独编译,也可以不做任何修改就和整个程序的整体进行无缝衔接的编译.具体的思路是借助第三方文件,将子模块编译好的.o文件的路径自动写到confi ...

  8. 2017年学习的三个CSS新特性

    这是翻译的一篇文章,原文是:3 New CSS Features to Learn in 2017,翻译的不是很好,如有疑问欢迎指出. 新的一年,我们有一系列新的东西要学习.尽管CSS有很多新的特性, ...

  9. ubuntu开机自动关闭独显,使用集成显卡

    我的本子是联想y470p-ise,因为是有双显卡,而ubuntu在开机后,双显卡默认是同时工作,会产生巨大的发热,导致很不爽.而且在ubuntu下基本我也不用独显,所以有开机关闭独显的需求. ubun ...

  10. 2016 ACM/ICPC Asia Regional Qingdao Online(2016ACM青岛网络赛部分题解)

    2016 ACM/ICPC Asia Regional Qingdao Online(部分题解) 5878---I Count Two Three http://acm.hdu.edu.cn/show ...