洛谷 P2932 [USACO09JAN]地震造成的破坏Earthquake Damage
题目描述
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)
输入输出样例
说明
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的更多相关文章
- P2932 [USACO09JAN]地震造成的破坏Earthquake Damage 爆搜
这题怎么这么水~~~本来以为挺难的一道题,结果随便一写就过了...本来还不知道损坏的牛棚算不算,结果不明不白就过了... 题干: 农夫John的农场遭受了一场地震.有一些牛棚遭到了损坏,但幸运地,所有 ...
- 2018.07.06 洛谷P2936 [USACO09JAN]全流Total Flow(最大流)
P2936 [USACO09JAN]全流Total Flow 题目描述 Farmer John always wants his cows to have enough water and thus ...
- 洛谷2944 [USACO09MAR]地震损失2Earthquake Damage 2
https://www.luogu.org/problem/show?pid=2944 题目描述 Wisconsin has had an earthquake that has struck Far ...
- 洛谷——P2935 [USACO09JAN]最好的地方Best Spot
P2935 [USACO09JAN]最好的地方Best Spot 题目描述 Bessie, always wishing to optimize her life, has realized that ...
- 「洛谷P1343」地震逃生 解题报告
P1343 地震逃生 题目描述 汶川地震发生时,四川XX中学正在上课,一看地震发生,老师们立刻带领x名学生逃跑,整个学校可以抽象地看成一个有向图,图中有n个点,m条边.1号点为教室,n号点为安全地带, ...
- ●洛谷P2934 [USACO09JAN]安全出行Safe Travel
题链: https://www.luogu.org/problemnew/show/P2934 题解: 最短路(树),可并堆(左偏堆),并查集. 个人感觉很好的一个题. 由于题目已经明确说明:从1点到 ...
- 洛谷——P2936 [USACO09JAN]全流Total Flow
题目描述 Farmer John always wants his cows to have enough water and thus has made a map of the N (1 < ...
- 【洛谷P1343】地震逃生
一道傻吊的网络流题,wori我写的读入优化怎么老T? 远离读入优化报平安? #include<bits/stdc++.h> #define N 4005 #define inf 10000 ...
- 洛谷 P2935 [USACO09JAN]最好的地方Best Spot
题目描述 Bessie, always wishing to optimize her life, has realized that she really enjoys visiting F (1 ...
随机推荐
- Linux环境thinkphp配置以及数据源驱动改动
项目中须要用到thinkphp,以下简称tp. linux版本号:64位CentOS 6.4 Nginx版本号:nginx1.8.0 php版本号:php5.5.28 thinkphp版:3.2.3 ...
- 读配置文件能够保持顺序的 Java Properties 类
序 前几天,公司项目中有一个需求是读取配置文件的.并且最好可以保证载入到内存中的顺序可以和配置文件里的顺序一致,可是.假设使用 jdk 中提供的 Properties 类的话,读取配置文件后.载入到内 ...
- ELF文件格式定义
ELF(Executable and Linking Format)是一种对象文件的格式,用于定义不同类型的对象文件(Object files)中都放了什么东西.以及都以什么样的格式去放这些东西.它自 ...
- iOS-UIApplication详解
UIApplication简介 UIApplication对象是应用程序的象征. 每一个应用程序都有自己的UIApplication对象,而且是单例. 一个iOS程序启动后创建的第一个对象就是UIAp ...
- checkbox的使用总结
1 checkbox如何选中时显示内容,不被选中时隐藏内容 <!DOCTYPE html> <html> <head> <meta name="vi ...
- BZOJ 3674/BZOJ 3673 主席树
思路: 主席树维护可持久化数组 剩下的就是普通的并查集了- //By SiriusRen #include <cstdio> #include <cstring> #inclu ...
- Linux下安装 php-memcache 扩展
需要的库:yum install -y libmemcached libmemcached-devel 下载:https://pecl.php.net/package/memcached 安装: un ...
- layer-list
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android=" ...
- DataBaseFactory基础了解
<add name="Connection str" connectionString="data source=.;pwd=12;uid=sa;database ...
- thinkphp5 模板中截取中文字符串
TP5模板页截取中文字符串 {$vo.task_detail|mb_substr=###,0,15,'utf-8'}