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

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. Run Loop简介 分类: ios技术 ios相关 2015-03-11 22:21 73人阅读 评论(0) 收藏

    做了一年多的IOS开发,对IOS和Objective-C深层次的了解还十分有限,大多还停留在会用API的级别,这是件挺可悲的事情.想学好一门语言还是需要深层次的了解它,这样才能在使用的时候得心应手,出 ...

  2. mysql server的安装和配置

    YSQL-5.7.9.1解压版 例如我的在D:\Program Files\MySQL\MySQL Server 5.7(解压时名字mysql-installer-community-5.7.9.1可 ...

  3. SpringBoot JPA实现增删改查、分页、排序、事务操作等功能

    今天给大家介绍一下SpringBoot中JPA的一些常用操作,例如:增删改查.分页.排序.事务操作等功能.下面先来介绍一下JPA中一些常用的查询操作: //And --- 等价于 SQL 中的 and ...

  4. GOLang(数组操作随篇)

    创建一个类似PHP Array $data["userInfo"] = ["name"=>"Josn","ages" ...

  5. vdi、vhd、vmdk虚拟格式转换

    VirtualBox带来VBoxManager.exe,可以来转换格式. 命令如下(Windows环境,Linux版的应该也有VBoxManager这个二进制文件): VBoxManager存在于Vi ...

  6. oc是一个全动态语言,oc的一切都是基于runtime实现的!

    oc是一个全动态语言,oc的一切都是基于runtime实现的! 从以下三方面来理解runtime吧! 1. 传统的面向过程的语言开发,例如c语言.实现c语言编译器很简单,只要按照语法规则实现一个LAL ...

  7. CentOS6.5+mysql5.5源码安装

    数据库安装 1新增mysql用户 [root@HE1mysql]# groupadd mysql -g 502 [root@HE1mysql]# useradd -g mysql -s /sbin/n ...

  8. Raphael初始化,path,circle,rect,ellipse,image

    path jsp: <%@ page language="java" contentType="text/html; charset=UTF-8" pag ...

  9. Bootstrap相关的网站

    http://www.bootcss.com/ http://expo.bootcss.com/ http://www.webresourcesdepot.com/20-beautiful-resou ...

  10. 有效的GOCsharpHelper1.0(源代码开放)

    csharp编写界面,调用基于opencv的图像处理类库,是解决一类问题的优良方法.经过不懈研究,有最新进展: 一.目前情况和优点        位置在11.通过clr             架在c ...