洛谷 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 ...
随机推荐
- jsp 传值jsp 数据库 乱码解决的攻略 全套
jsp传值给jsp中文乱码 传值给数据库乱码的解决方法 所有的用到编码的所有统一utf-8 1.装mysql的时候有选择编码的界面的那个地方选utf-8编码 2 建数据库的时候选择 字符集 排序规则所 ...
- 在linux環境下安裝jprofiler_linux_8_0_2.sh
1.安装jprofiler_linux_8_0_2.sh chmod+x jprofiler_linux_8_0_2.sh ./jprofiler_linux_8_0_2.sh –c 安装过程略..差 ...
- 基于servlet实现一个web框架
servlet作为一个web规范.其本身就算做一个web开发框架,可是其web action (响应某个URI的实现)的实现都是基于类的,不是非常方便,而且3.0之前的版本号还必须通过web.xml配 ...
- BroadcastReceiver类
java.lang.Object ↳ android.content.BroadcastReceiver 已知直接子类 AppWidgetProvider DeviceAdminReceiver ...
- 读取excel模板填充数据 并合并相同文本单元格
try { string OutFileName = "北京市国控企业污染源废气在线比对监测数据审核表" + DateTime.Now.ToString(& ...
- 英语发音规则---T字母
英语发音规则---T字母 一.总结 一句话总结: 1.T一般发[t]? ten [ten] num.十 letter [ˈletə(r)] n.信; 证书 meet [mi:t] vt.& v ...
- DNS隧道之DNS2TCP实现——dns2tcpc必须带server IP才可以,此外ssh可以穿过墙的,设置代理上网
我自己的命令: server端: dns2tcpd -F -d 1 -f ./dns2tcpd.conf 输出: 09:08:59 : Debug options.c:97 Add resource ...
- EOJ 3000 ROT13加密和解密
应用 ROT13 到一段文字上仅仅只需要检查字母顺序并取代它在 13 位之后的对应字母,有需要超过时则重新绕回 26 英文字母开头即可.A 换成 N.B 换成 O.依此类推到 M 换成 Z,然后串行反 ...
- ROS集成开发环境RoboWare Studio安装教程
前言:很多人说vim是最快的,所以我选择用roboware. ROS 自带的编辑器vim增加插件,效果如下: RoboWare Studio,效果如下: 下面开始安装. 一.安装 去官网 http:/ ...
- layui序章
layui,layer,laydate关系图,layer和laydate作为layui的独立模块存在 下载地址:layer.layui.com