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 ...
随机推荐
- IOS8 设置TableView Separatorinset 分割线从边框顶端开始
IOS8 设置TableView Separatorinset 分割线从边框顶端开始 在ios8上 [TableViewsetSeparatorInset:UIEdgeInsetsMake(0,0 ...
- 一周学会Mootools 1.4中文教程:(3)事件
今天我們講解一下mt的事件部分,对于事件的讲解主要包含三部分,分别是:绑定,移除,和触发,我们首先来看一个例子 //jquery的事件绑定方式$('a').click(function){ alert ...
- codeforces 633C. Spy Syndrome 2 hash
题目链接 C. Spy Syndrome 2 time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- java反编译命令javap
1. 输出所有类和成员 javap -private XX.class 2. 输出分解后的代码 javap -c XX.class
- SQL语句的MINUS,INTERSECT和UNION ALL
SQL语句中的三个关键字:MINUS(减去),INTERSECT(交集)和UNION ALL(并集); 关于集合的概念,中学都应该学过,就不多说了.这三个关键字主要是对数据库的查询结果进行操作,正如其 ...
- Y5V贴片电容(MLCC)容量范围速查表
Y5V贴片电容简述 Y5V贴片电容属于EIA规定的Class 2类材料的电容.它的电容量受温度.电压.时间变化影响大. Y5V贴片电容特性 具有较差的电容量稳定性,在-25℃-85℃工作温度范围内,温 ...
- FTL(Flash translation layer)闪存转换层
前面说过,闪存的读写单位为页,而页的大小一般为4KB或8KB,但我们的操作系统读写数据是按HDD的扇区尺寸进行的(512Byte(字节)),更麻烦的是闪存擦除以块作单位,而且未擦除就无法写入,这导致操 ...
- 转:CSS Overflow 属性
原文:CSS Overflow 属性译自:The CSS Overflow Property版权所有,转载请注明出处,多谢!! 根据CSS的盒模型概念,页面中的每个元素,都是一个矩形的盒子.这些盒子的 ...
- Android利用tcpdump和wireshark抓取网络数据包
Android利用tcpdump和wireshark抓取网络数据包 主要介绍如何利用tcpdump抓取andorid手机上网络数据请求,利用Wireshark可以清晰的查看到网络请求的各个过程包括三次 ...
- 【c语言】推断一个数是不是2的n次方
// 推断一个数是不是2的n次方 #include <stdio.h> void judge_n(int a) { int b = a - 1; if ((a & b) == 0) ...