传送门

告诉你一些点不能到达1,由于是双向边,也就是1不能到达那些点

那么从1开始dfs,如果当前点能到达不能到达的点,那么当前点就是损坏的。

#include <cstdio>
#include <cstring>
#include <iostream>
#define N 100001 int n, m, p, cnt, tot;
int head[N], to[N << 1], next[N << 1];
bool vis[N], flag[N]; inline int read()
{
int x = 0, f = 1;
char ch = getchar();
for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
for(; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
return x * f;
} inline void add(int x, int y)
{
to[cnt] = y;
next[cnt] = head[x];
head[x] = cnt++;
} inline void dfs(int u)
{
int i, v;
vis[u] = 1;
for(i = head[u]; i ^ -1; i = next[i])
{
v = to[i];
if(flag[v]) return;
}
for(i = head[u]; i ^ -1; i = next[i])
{
v = to[i];
if(!vis[v]) dfs(v);
}
tot++;
} int main()
{
int i, x, y;
n = read();
m = read();
p = read();
memset(head, -1, sizeof(head));
for(i = 1; i <= m; i++)
{
x = read();
y = read();
add(x, y);
add(y, x);
}
for(i = 1; i <= p; i++)
{
x = read();
flag[x] = 1;
}
dfs(1);
printf("%d\n", n - tot);
return 0;
}

  

[BZOJ1574] [Usaco2009 Jan]地震损坏Damage(贪心 + dfs)的更多相关文章

  1. bzoj1574 [Usaco2009 Jan]地震损坏Damage

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1574 [题解] 贪心把report的点的旁边所有点破坏即可. # include <s ...

  2. bzoj 1574: [Usaco2009 Jan]地震损坏Damage【dfs】

    和March的那道不一样,只是非常单纯的带着贪心的dfs 首先一个点被隔断,与它相邻的所有点也会被隔断,打上删除标记,从1dfs即可 #include<iostream> #include ...

  3. 1574: [Usaco2009 Jan]地震损坏Damage

    1574: [Usaco2009 Jan]地震损坏Damage Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 425  Solved: 232[Subm ...

  4. [bzoj1574][Usaco2009 Jan]地震损坏Damage_dfs

    地震损坏Damage bzoj-1574 Usaco-2009 Jan 题目大意:题目链接. 注释:略. 想法: 显然对于每一个report点,和它直接相连的点都不可能到达1.我们将它打上标记. 然后 ...

  5. BZOJ 1574: [Usaco2009 Jan]地震损坏Damage

    Description 农夫John的农场遭受了一场地震.有一些牛棚遭到了损坏,但幸运地,所有牛棚间的路经都还能使用. FJ的农场有P(1 <= P <= 30,000)个牛棚,编号1.. ...

  6. P1574: [Usaco2009 Jan]地震损坏Damage

    卧槽卧槽卧槽,这道水题竟然让我WA了两遍!!评测系统卡了然后手贱又提交了一次,然后就悲催了呜呜.. 把与不能回家但牛棚完好的牛相邻的牛棚赋值为不能走(false),可以证明,如果该牛回不了家,则周围一 ...

  7. 【BZOJ】1574: [Usaco2009 Jan]地震损坏Damage

    [算法]搜索 [题意]给定无向图,现在可能有一些点已经被删除,只给出信息是c个点不能到达结点1,求最少的不能到达结点1的个数(含已删除点). [题解] 真是一道奥妙重重的题目. 每个点不能到达结点1, ...

  8. BZOJ3396: [Usaco2009 Jan]Total flow 水流

    3396: [Usaco2009 Jan]Total flow 水流 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 45  Solved: 27[Sub ...

  9. 3396: [Usaco2009 Jan]Total flow 水流

    3396: [Usaco2009 Jan]Total flow 水流 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 179  Solved: 73[Su ...

随机推荐

  1. Android笔记--Bitmap(三) 针对不用Android版本的位图管理

    Bitmap(三) | Android不同版本的相应操作 在不同的Android版本中.位图的存储方式是不同的. 1.小于等于 Android 2.2 (API level 8) 垃圾收集器回收内存时 ...

  2. linux_base-f10-10_7 linuxulator is not (kld)loaded

    # cd linux_base-f10/# make install clean===>  linux_base-f10-10_7 linuxulator is not (kld)loaded. ...

  3. bat 批处理测试局域网速度 两端电脑

    C:\Users\Administrator>iperf3 iperf3: parameter error - must either be a client (-c) or server (- ...

  4. 洛谷 P1376 机器工厂

    题目描述 小T开办了一家机器工厂,在N(N<=10000)个星期内,原材料成本和劳动力价格不断起伏,第i周生产一台机器需要花费Ci(1<=Ci<=5000)元.若没把机器卖出去,每保 ...

  5. kvc to nsdata

        [NSKeyedArchiver archivedDataWithRootObject:arr];    [NSKeyedUnarchiver unarchiveObjectWithData: ...

  6. CSS的相对定位和绝对定位

     relative的意思就是相对自己的一开始的位置进行的定位.如图: 但是这个元素的本身边距不变,还在原来位置   absolute的意思就是 如果它的父元素设置了除static之外的定位,比如pos ...

  7. GUI进化--数据与界面分离

    http://blog.csdn.net/doon/article/details/5946862 1.何谓数据和界面分离? GUI,即Graphic User Interface,人机交换界面.连接 ...

  8. WPF中的TextBlock处理长字符串

    Xaml: <StackPanel> <TextBlock Margin="10" Foreground="Red"> This is ...

  9. JAVA web项目转客户端(nativefier)

    1.环境:windows 2.下载node.js 3.安装mode.js;记住安装目录 4.命令行进入安装目录 5.执行语句: npm install nativefier –g 进行安装 6.新建空 ...

  10. Bootstrap历练实例:弹出提示信息的样式按钮

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...