BZOJ 3402: [Usaco2009 Open]Hide and Seek 捉迷藏
题目
3402: [Usaco2009 Open]Hide and Seek 捉迷藏
Time Limit: 3 Sec Memory Limit: 128 MB
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
题解
呃,这一题嘛。。就是一个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 捉迷藏的更多相关文章
- BZOJ—— 3402: [Usaco2009 Open]Hide and Seek 捉迷藏
http://www.lydsy.com/JudgeOnline/problem.php?id=3402 Description 贝茜在和约翰玩一个“捉迷藏”的游戏. 她正要找出所有适 ...
- BZOJ 3402: [Usaco2009 Open]Hide and Seek 捉迷藏(最短路)
这个= =一看就是最短路了= = PS:最近有点懒 = = 刚才看到一道平衡树的裸题还嫌懒不去写= =算了等刷完这堆水题再去理= = CODE: #include<cstdio>#incl ...
- 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 < ...
- BZOJ3402: [Usaco2009 Open]Hide and Seek 捉迷藏
3402: [Usaco2009 Open]Hide and Seek 捉迷藏 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 51 Solved: 4 ...
- B3402 [Usaco2009 Open]Hide and Seek 捉迷藏 最短路
直接最短路板子,dij堆优化. 题干: 题目描述 贝茜在和约翰玩一个“捉迷藏”的游戏. 她正要找出所有适合她躲藏的安全牛棚.一共有N(≤N≤)个牛棚,被编为1到N号.她知道约翰(捉牛者)从牛棚1出发. ...
- 【BZOJ】【1941】【SDOI2010】Hide and Seek
KD-Tree 一开始看错题了
- bzoj:1941: [Sdoi2010]Hide and Seek
1941: [Sdoi2010]Hide and Seek Time Limit: 16 Sec Memory Limit: 162 MBSubmit: 531 Solved: 295[Submi ...
- 洛谷 P2951 [USACO09OPEN]捉迷藏Hide and Seek
题目戳 题目描述 Bessie is playing hide and seek (a game in which a number of players hide and a single play ...
随机推荐
- ##DAY15——UICollectionView
DAY15——UICollectionView 创建UICollectionView //创建一个布局对象,采用系统布局类UICollectionViewFlowLayout UICollection ...
- android 文件操作类简易总结
android 文件操作类(参考链接) http://www.cnblogs.com/menlsh/archive/2013/04/02/2997084.html package com.androi ...
- CKEditor + CKFinder 实现编辑上传图片配置 (二)
CKEditor + CKFinder 实现编辑上传图片配置 (二) 上传图片时,如果上传的图片过大,默认情况情况下回自动裁剪,代码如图 \ckfinder\config.php 目录下的配置文件co ...
- php fpm start.sh
#! /bin/bash #Source function library. . /etc/init.d/functions #Check that networking is up. . /etc/ ...
- VC++学习之进程和线程的区别
VC++学习之进程和线程的区别 一.进程 进程是表示资源分配的基本单位,又是调度运行的基本单位.例如,用户运行自己的程序,系统就创建一个进程,并为它分配资源,包括各种表格.内存空间.磁盘 ...
- java计算器
由于自己的实验报告 需要用Java来写一个实验报告.自己本没有怎么学过Java,但是学的话也就认真的学一下,毕竟技术这条路线是技多不压身.于是在网站上找来了一些资料,关于Java到底是干什么的, ...
- 使用SWFUpload插件上传文件
演示代码由两部分组成,包括前台文件和后台文件: 1.前台文件index.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transi ...
- Python的maketrans() 方法
描述 Python maketrans() 方法用于创建字符映射的转换表,对于接受两个参数的最简单的调用方式,第一个参数是字符串,表示需要转换的字符,第二个参数也是字符串表示转换的目标. 注:两个字符 ...
- [C语言练习]学生学籍管理系统
/** * @copyright 2012 Chunhui Wang * * wangchunhui@wangchunhui.cn * * 学生学籍管理系统(12.06) */ #include &l ...
- hdu4491 Windmill Animation(计算几何)
Windmill Animation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...