传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1574

【题解】

贪心把report的点的旁边所有点破坏即可。

# include <stdio.h>
# include <string.h>
# include <iostream>
# include <algorithm>
// # include <bits/stdc++.h> using namespace std; typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int M = 5e5 + ;
const int mod = 1e9+; # define RG register
# define ST static int n, m, K, p[M];
bool isr[M];
int head[M], nxt[M], to[M], tot=; inline void add(int u, int v) {
++tot; nxt[tot] = head[u]; head[u] = tot; to[tot] = v;
}
inline void adde(int u, int v) {
add(u, v), add(v, u);
} bool vis[M];
int ans = ;
inline void dfs(int x) {
vis[x] = ; ++ans;
for (int i=head[x]; i; i=nxt[i])
if(!vis[to[i]]) dfs(to[i]);
} int main() {
cin >> n >> m >> K;
for (int i=, u, v; i<=m; ++i) {
scanf("%d%d", &u, &v);
adde(u, v);
}
for (int i=; i<=K; ++i) {
scanf("%d", p+i);
isr[p[i]] = ;
}
for (int i=, x; i<=K; ++i) {
for (int j=head[p[i]]; j; j=nxt[j]) {
x = to[j];
if(!isr[x]) vis[x] = ;
}
}
dfs();
cout << n-ans;
return ;
}

bzoj1574 [Usaco2009 Jan]地震损坏Damage的更多相关文章

  1. [BZOJ1574] [Usaco2009 Jan]地震损坏Damage(贪心 + dfs)

    传送门 告诉你一些点不能到达1,由于是双向边,也就是1不能到达那些点 那么从1开始dfs,如果当前点能到达不能到达的点,那么当前点就是损坏的. #include <cstdio> #inc ...

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

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

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

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

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

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

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

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

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

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

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

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

  8. bzoj 1576: [Usaco2009 Jan]安全路经Travel 树链剖分

    1576: [Usaco2009 Jan]安全路经Travel Time Limit: 10 Sec  Memory Limit: 64 MB Submit: 665  Solved: 227[Sub ...

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

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

随机推荐

  1. EF报错“EntityValidationErrors”

          在使用EF更新实体的时候报错,显示界面如下:       点击查看详情:        在查看详细的窗体中,EntityValidationErrors里面的也看不到具体的错误原因.在网上 ...

  2. Python-学习-项目1-即时标记-1

    买了一本Python入门,奈何看不下去,只能是先看后面的项目,看到那里不懂的时候在回去学习. 项目名字:即时标记 大致的意思就是把一个纯文本文件标记成自己想要的格式文件. 首先就是待处理文本,我找不到 ...

  3. 51单片机数码管字符H自右向左移动

    #include <reg51.h> #define uint unsigned int #define uchar unsigned char sfr P0M0 = 0x94; sfr ...

  4. 问题 B: Prime Number

    题目描述 Output the k-th prime number. 输入 k≤10000 输出 The k-th prime number. 样例输入 10 50 样例输出 29 229 #incl ...

  5. Week2 Teamework from Z.XML 软件分析与用户需求调查(三)必应助手体验评测

    评测人:毛宇 肖俊鹏 说明:言辞激烈,请勿介意 我花了2天的时间来试用这个软件<必应缤纷桌面手机助手>,有了很多体会,这里,我来谈一下这款软件在体验部分的表现情况. 体验部分主要分为三个部 ...

  6. Internet History,Technology and Security

    Internet History,Technology and Security(简单记录) First Week High Stakes Research in Computing,and Comm ...

  7. exec族

    在之前我们已经知道用fork创建子进程后执行的是和父进程相同的程序(但有可能执行不同的代码分支),子进程往往要调用一种exec函数以执行另一个程序.当进程调用一种exec函数时,该进程的用户空间代码和 ...

  8. Extjs的API阅读方式(整理)

    原文链接:http://www.cnblogs.com/gaojun/archive/2013/05/28/3103908.html

  9. [CCF] 201612-2 工资计算

    [思路]按照题意对初始工资S进行循环,计算缴税后工资,若与T相等则退出循环,输出结果. #include <iostream> #include <windows.h> usi ...

  10. P1368 工艺

    题目描述 小敏和小燕是一对好朋友. 他们正在玩一种神奇的游戏,叫Minecraft. 他们现在要做一个由方块构成的长条工艺品.但是方块现在是乱的,而且由于机器的要求,他们只能做到把这个工艺品最左边的方 ...