题目描述

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. BA-Johnson楼控简介

  2. http数据绑定spring mvc详解

  3. &lt;监听器模式&gt;在C++ 与 Java 之间实现的差异

    前言: 关于各种语言孰优孰劣的讨论在软件界就是个没完没了的话题,今天我决定也来掺和下. 只是我想探讨的不是哪种语言的性能怎样,钱途怎样.而是站在语言本身特性的基础上中肯地比較探讨.由于如今工作用的是C ...

  4. [Phonegap+Sencha Touch] 移动开发19 某些安卓手机上弹出消息框 点击后不消失的解决的方法

    Ext.Msg.alert等弹出框在某些安卓手机上,点击确定后不消失. 原因是: 消息框点击确定后有一段css3 transform动画,动画完毕后才会隐藏(display:none). 有些奇葩手机 ...

  5. html与JacaScript中的重要思想:预留后路、向后兼容、js分离

    以一个简单的web程序为例 详细设计模式请配合代码及凝视食用 <!DOCTYPE html> <!-- 1 预留退路:假设用户禁用了js.链接还能正常显示吗?(href) 2 分离j ...

  6. C# First and FirstOrDefault 方法详解

    在工作中我们经常会遇到有关LINQ 的一些问题.这时我们就用到lambda 表达式. 下面是我在工作遇到的. First  and FirstOrDefault  这两方法.我今天把它记录一下. 需要 ...

  7. 12.Matlab神经网络工具箱

    概述: 1 人工神经网络介绍 2 人工神经元 3 MATLAB神经网络工具箱 4 感知器神经网络 5 感知器神经网络 5.1 设计实例分析 clear all; close all; P=[ ; ]; ...

  8. 微信小程序分享朋友圈的实现思路与解决办法

    实现思路 那么既然小程序没有分享到朋友圈的api,我们怎么实现分享到朋友圈呢,下面我介绍一下实现思路. 既然没有捷径,那就走复杂一点的路线,那就是需要用户手动分享到朋友圈,问题又来了,用户手动分享的话 ...

  9. 用过的jQuery记录

    var list= $('input:radio[name="name"]:checked').val(); //选择input中单选name为“name”的并且是选中状态的 in ...

  10. Android Handler学习笔记

    已经习惯了挖坑不填,继续任性一下,周一到周五继续挖坑,每周六周日负责填坑. 1.从Android UI线程谈起 出于性能考虑,Android 中的UI操作并不是线程安全的,所以Android中规定只能 ...