题目描述

Wisconsin has had an earthquake that has struck Farmer John's farm! The earthquake has damaged some of the pastures so that they are unpassable. Remarkably, none of the cowpaths was damaged.

As usual, the farm is modeled as a set of P (1 <= P <= 30,000) pastures conveniently numbered 1..P which are connected by a set of C (1 <= C <= 100,000) non-directional cowpaths conveniently numbered 1..C. Cowpath i connects pastures a_i and b_i (1 <= a_i <= P; 1 <= b_i <= P). Cowpaths might connect a_i to itself or perhaps might connect two pastures more than once. The barn is located in pasture 1.

A total of N (1 <= N <= P) cows (in different pastures) sequentially contact Farmer John via moobile phone with an integer message

report_j (2 <= report_j <= P) that indicates that pasture report_j is undamaged but that the calling cow is unable to return to the barn from pasture report_j because she could not find a path that does not go through damaged pastures.

After all the cows report in, determine the minimum number of

pastures (including ones that are uncrossable) from which it is not possible to return to the barn.

Note: Feedback on some of the test data will be provided on the first 50 submissions

农夫John的农场遭受了一场地震.有一些牛棚遭到了损坏,但幸运地,所有牛棚间的路经都还能使用. FJ的农场有P(1 <= P <= 30,000)个牛棚,编号1..P. C(1 <= C <= 100,000)条双向路经联接这些牛棚,编号为1..C. 路经i连接牛棚a_i和b_i (1 <= a_i<= P;1 <= b_i <= P).路经可能连接a_i到它自己,两个牛棚之间可能有多条路经.农庄在编号为1的牛棚. N (1 <= N <= P)头在不同牛棚的牛通过手机短信report_j(2 <= report_j <= P)告诉FJ它们的牛棚(report_j)没有损坏,但是它们无法通过路经和没有损坏的牛棚回到到农场. 当FJ接到所有短信之后,找出最小的不可能回到农庄的牛棚数目.这个数目包括损坏的牛棚. 注意:前50次提交将提供在一些测试数据上的运行结果.

输入输出格式

输入格式:

* Line 1: Three space-separated integers: P, C, and N

* Lines 2..C+1: Line i+1 describes cowpath i with two integers: a_i and b_i

* Lines C+2..C+N+1: Line C+1+j contains a single integer: report_j

输出格式:

* Line 1: A single integer that is the minimum count of pastures from which a cow can not return to the barn (including the damaged pastures themselves)

输入输出样例

输入样例#1: 复制

4 3 1
1 2
2 3
3 4
3
输出样例#1: 复制

3

说明

Pasture 2 is damaged, resulting in cows in pastures 2, 3, 4 not being able to return to the barn.

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define M 30005
using namespace std;
int n,m,k;
int ans,tot;
int vis[M],head[M];
int to[M*],net[M*];
void add(int i,int j){
to[++tot]=j;net[tot]=head[i];head[i]=tot;
to[++tot]=i;net[tot]=head[j];head[j]=tot;
}
void del(int x){
for(int i=head[x];i;i=net[i])
vis[to[i]]=;
}
void dfs(int x){
vis[x]=;ans--;
for(int i=head[x];i;i=net[i])
if(!vis[to[i]]) dfs(to[i]);
}
int main(){
scanf("%d%d%d",&n,&m,&k);
ans=n;
for(int i=;i<=m;i++){
int x,y;scanf("%d%d",&x,&y);
add(x,y);
}
for(int i=;i<=k;i++){
int x;scanf("%d",&x);
del(x);
}
dfs();
printf("%d\n",ans);
}

洛谷 P2932 [USACO09JAN]地震造成的破坏Earthquake Damage的更多相关文章

  1. P2932 [USACO09JAN]地震造成的破坏Earthquake Damage 爆搜

    这题怎么这么水~~~本来以为挺难的一道题,结果随便一写就过了...本来还不知道损坏的牛棚算不算,结果不明不白就过了... 题干: 农夫John的农场遭受了一场地震.有一些牛棚遭到了损坏,但幸运地,所有 ...

  2. 2018.07.06 洛谷P2936 [USACO09JAN]全流Total Flow(最大流)

    P2936 [USACO09JAN]全流Total Flow 题目描述 Farmer John always wants his cows to have enough water and thus ...

  3. 洛谷2944 [USACO09MAR]地震损失2Earthquake Damage 2

    https://www.luogu.org/problem/show?pid=2944 题目描述 Wisconsin has had an earthquake that has struck Far ...

  4. 洛谷——P2935 [USACO09JAN]最好的地方Best Spot

    P2935 [USACO09JAN]最好的地方Best Spot 题目描述 Bessie, always wishing to optimize her life, has realized that ...

  5. 「洛谷P1343」地震逃生 解题报告

    P1343 地震逃生 题目描述 汶川地震发生时,四川XX中学正在上课,一看地震发生,老师们立刻带领x名学生逃跑,整个学校可以抽象地看成一个有向图,图中有n个点,m条边.1号点为教室,n号点为安全地带, ...

  6. ●洛谷P2934 [USACO09JAN]安全出行Safe Travel

    题链: https://www.luogu.org/problemnew/show/P2934 题解: 最短路(树),可并堆(左偏堆),并查集. 个人感觉很好的一个题. 由于题目已经明确说明:从1点到 ...

  7. 洛谷——P2936 [USACO09JAN]全流Total Flow

    题目描述 Farmer John always wants his cows to have enough water and thus has made a map of the N (1 < ...

  8. 【洛谷P1343】地震逃生

    一道傻吊的网络流题,wori我写的读入优化怎么老T? 远离读入优化报平安? #include<bits/stdc++.h> #define N 4005 #define inf 10000 ...

  9. 洛谷 P2935 [USACO09JAN]最好的地方Best Spot

    题目描述 Bessie, always wishing to optimize her life, has realized that she really enjoys visiting F (1 ...

随机推荐

  1. 洛谷 U3346 A1-偶回文数

    U3346 A1-偶回文数 题目背景 方方方很喜欢回文数,于是zzq就出了一道关于回文数的题目. 因为偶回文数比较简单,所以方方方就把它放在了第一题... 题目描述 我们定义一个长度为偶数的回文数叫做 ...

  2. Java多线程演示样例(模拟通话,sleep,join,yield,wait,notify,Semaphore)

    主线程等待子线程的多种方法 synchronized浅析 sleep 是静态方法,Thread.sleep(xx)谁调用谁睡眠. join 是合并方法.当前线程调用其它线程xx.join()则等到xx ...

  3. 彻底禁用resource manager

    禁用resource manager 由于发现系统的一个等待事件:resmgr:cpu quantum.这是由于resource manager的原因.看来resource manager 的bug还 ...

  4. poj 2683 Ohgas&#39; Fortune 利率计算

    水题. 代码: //poj 2683 //sep9 #include <iostream> using namespace std; int main() { int cases; sca ...

  5. 深刻理解Nginx之基本配置和升级(2)

    3 Nginx基本配置 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvam9obl9mX2xhdQ==/font/5a6L5L2T/fontsize/400 ...

  6. 视差滚动demo (pc)

    根据设计图设定每屏的高度,js会自动缩放到全屏尺寸,效果要大尺寸才能看的出来 demo :http://runjs.cn/detail/uvizsekd <!DOCTYPE html> & ...

  7. oracle如何创建数据库

    第一步: 从Windows桌面执行“开始”→“Database Configuration Assistant”命令,打开Database Configuration Assistant对话框的欢迎界 ...

  8. redis 五大数据类型的常用指令

    STRING 192.168.1.66:6379> get k1 "v1" 192.168.1.66:6379> append k1 12345 (integer) 7 ...

  9. IPK僵尸网络 看看其传播手法

    转自:http://www.freebuf.com/vuls/154975.html 一.IPK僵尸网络概述 IPK僵尸家族是自2012年底就开始出现并长期持续活跃在境外的DDoS僵尸网络.2016年 ...

  10. linux HBA 卡驱动安装

    系统环境操作系统 : RHEL5.0设备 DL580G5  HBA 卡:Qlogic 2343连接存储: EVA8100---------------------------------------- ...