[bzoj1574][Usaco2009 Jan]地震损坏Damage_dfs
地震损坏Damage bzoj-1574 Usaco-2009 Jan
题目大意:题目链接。
注释:略。
想法:
显然对于每一个report点,和它直接相连的点都不可能到达1。我们将它打上标记。
然后爆搜。不搜经过的店,不搜标记的点。
显然,这样所有可以被到达的点都符合题意,用n减一下就行了。
最后,附上丑陋的代码... ...
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 30010
#define M 100010
int head[N],nxt[M<<1],to[M<<1],tot;
inline void add(int x,int y) {to[++tot]=y; nxt[tot]=head[x]; head[x]=tot;}
inline void Add(int x,int y) {add(x,y); add(y,x);}
bool cut[N];
bool vis[N];
void dfs(int pos)
{
vis[pos]=1;
for(int i=head[pos];i;i=nxt[i]) if(!cut[to[i]]&&!vis[to[i]])
{
dfs(to[i]);
}
}
int main()
{
int n,m,p;
scanf("%d%d%d",&n,&m,&p);
int a,b,x;
for(int i=1;i<=m;++i)
{
scanf("%d%d",&a,&b);
Add(a,b);
}
while(p--)
{
scanf("%d",&x);
for(int i=head[x];i;i=nxt[i])
cut[to[i]]=1;
}
dfs(1);
int ans=n;
for(int i=1;i<=n;++i)
if(vis[i])
--ans;
printf("%d",ans);
return 0;
}
小结:做问题时,如果已经得到了一种非常显然的结论,不要停止。尝试可不可能通过这个结论解出这个题或者直接得到更优美的结论。
[bzoj1574][Usaco2009 Jan]地震损坏Damage_dfs的更多相关文章
- [BZOJ1574] [Usaco2009 Jan]地震损坏Damage(贪心 + dfs)
传送门 告诉你一些点不能到达1,由于是双向边,也就是1不能到达那些点 那么从1开始dfs,如果当前点能到达不能到达的点,那么当前点就是损坏的. #include <cstdio> #inc ...
- bzoj1574 [Usaco2009 Jan]地震损坏Damage
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1574 [题解] 贪心把report的点的旁边所有点破坏即可. # include <s ...
- 1574: [Usaco2009 Jan]地震损坏Damage
1574: [Usaco2009 Jan]地震损坏Damage Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 425 Solved: 232[Subm ...
- BZOJ 1574: [Usaco2009 Jan]地震损坏Damage
Description 农夫John的农场遭受了一场地震.有一些牛棚遭到了损坏,但幸运地,所有牛棚间的路经都还能使用. FJ的农场有P(1 <= P <= 30,000)个牛棚,编号1.. ...
- P1574: [Usaco2009 Jan]地震损坏Damage
卧槽卧槽卧槽,这道水题竟然让我WA了两遍!!评测系统卡了然后手贱又提交了一次,然后就悲催了呜呜.. 把与不能回家但牛棚完好的牛相邻的牛棚赋值为不能走(false),可以证明,如果该牛回不了家,则周围一 ...
- 【BZOJ】1574: [Usaco2009 Jan]地震损坏Damage
[算法]搜索 [题意]给定无向图,现在可能有一些点已经被删除,只给出信息是c个点不能到达结点1,求最少的不能到达结点1的个数(含已删除点). [题解] 真是一道奥妙重重的题目. 每个点不能到达结点1, ...
- bzoj 1574: [Usaco2009 Jan]地震损坏Damage【dfs】
和March的那道不一样,只是非常单纯的带着贪心的dfs 首先一个点被隔断,与它相邻的所有点也会被隔断,打上删除标记,从1dfs即可 #include<iostream> #include ...
- bzoj 1576: [Usaco2009 Jan]安全路经Travel 树链剖分
1576: [Usaco2009 Jan]安全路经Travel Time Limit: 10 Sec Memory Limit: 64 MB Submit: 665 Solved: 227[Sub ...
- BZOJ3396: [Usaco2009 Jan]Total flow 水流
3396: [Usaco2009 Jan]Total flow 水流 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 45 Solved: 27[Sub ...
随机推荐
- ACM_Plants vs. Zombies(一元一次方程)
Plants vs. Zombies Time Limit: 2000/1000ms (Java/Others) Problem Description: There is a zombie on y ...
- D. Fedor and coupons 二分暴力
http://codeforces.com/contest/754/problem/D 给出n条线段,选出k条,使得他们的公共部分长度最大. 公共部分的长度,可以二分出来,为val.那么怎么判断有k条 ...
- Javascript DOM 编程艺术(第二版)读书笔记——DOM基础
1.DOM是什么 D=document(文档) O=object(对象) M=Model(模型) DOM又称节点树 一些术语: parent(父) child(子) sibling(兄弟) ...
- Server 2008 R2 事件查看器实现日志分析
在 windows server 2008 R2 中,可以通过点击 "开始" -> "管理工具" -> "事件查看器" ,来打开 ...
- 带有空格或tab的字符串的判断
class test { public static void main(String[] args) { String a = " "; //带有空格的字符串 if ( a.is ...
- java基础学习之垃圾回收机制
回收过程: 1.发现无用的对象 2.回收无用对象占用的内存的空间. 垃圾回收相关算法: 1.引用计数法 堆中每个对象都有一个引用计数.被引用一次,计数加一.被引用变量值变为null,则计数减一. 到计 ...
- oracle查询没有主键的表
select table_name from user_tables a where not exists (select * from user_constraints b where b.cons ...
- 【原】Python学习
1.常用模块介绍 #python -m SimpleHTTPServer 执行上面的命令就会在服务器当前目录下启动一个文件下载服务器,默认打开8000端口.这个时候,你只需要将IP和端口告诉客户端,即 ...
- c# Dictionary 扩展方法
主要用于接口请求,数据转换 #region Dictionary 扩展方法 public static string getString(this Dictionary<string, stri ...
- 面向对象程序设计--Java语言第三周编程题:查找里程
查找里程 题目内容: 下图为国内主要城市之间的公路里程: 你的程序要读入这样的一张表,然后,根据输入的两个城市的名称,给出这两个城市之间的里程. 注意:任何两个城市之间的里程都已经给出,不需要计算经第 ...