洛谷2944 [USACO09MAR]地震损失2Earthquake Damage 2
https://www.luogu.org/problem/show?pid=2944
题目描述
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 <= 3,000)
pastures conveniently numbered 1..P which are connected by a set of C (1 <= C <= 20,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 contacts 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 that are damaged.
地震袭击了威斯康星州,一些牧场被摧毁了.
一共有P个牧场.由C条双向路连接.两个牧场间可能有多条路.一条路也可能连接相同的牧场.牛棚坐落在牧场1.
N (1 <= N <= P) 只奶牛打来了求救电话,说她们的农场没有被摧毁,但是已经无法到达牛棚. 求出最少可能有多少牧场被摧毁.
输入输出格式
输入格式:
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: One number, the minimum number of damaged pastures.
输入输出样例
5 5 2
1 2
2 3
3 5
2 4
4 5
4
5
1
说明
Only pasture 2 being damaged gives such a scenario.
拆点!!!
#include<queue>
#include<cstdio>
#define N 3101
#define M 21001 using namespace std; const int inf=2e9; int n,c,p;
int src,decc,ans;
int front[N*],to[M*],nxt[M*],cap[M*],tot=;
int cnt[N*],lev[N*]; queue<int>q; void add(int u,int v,int w)
{
to[++tot]=v; nxt[tot]=front[u]; front[u]=tot; cap[tot]=w;
to[++tot]=u; nxt[tot]=front[v]; front[v]=tot; cap[tot]=;
}
bool bfs()
{
for(int i=;i<=p*+;i++)
lev[i]=-,cnt[i]=front[i];
while(!q.empty()) q.pop();
q.push(src); lev[src]=;
int now;
while(!q.empty())
{
now=q.front(); q.pop();
for(int i=cnt[now];i;i=nxt[i])
if(lev[to[i]]==- && cap[i])
{
lev[to[i]]=lev[now]+;
q.push(to[i]);
if(to[i]==decc) return true;
}
}
return false;
}
int dinic(int now,int flow)
{
if(now==decc) return flow;
int delta,rest=;
for(int &i=cnt[now];i;i=nxt[i])
{
if(cap[i] && lev[to[i]]>lev[now])
{
delta=dinic(to[i],min(flow-rest,cap[i]));
if(delta)
{
rest+=delta;
cap[i]-=delta; cap[i^]+=delta;
if(rest==flow) break;
}
}
}
if(rest!=flow) lev[now]=-;
return rest;
}
int main()
{
scanf("%d%d%d",&p,&c,&n);
decc=;
int u,v;
for(int i=;i<=p;i++) add(i<<|,i<<,);
for(int i=;i<=c;i++)
{
scanf("%d%d",&u,&v);
if(u==v) continue;
if(u==) add(v<<,,inf);
else if(v==) add(u<<,,inf);
else
{
add(u<<,v<<|,inf);
add(v<<,u<<|,inf);
}
}
for(int i=;i<=n;i++)
{
scanf("%d",&u);
add(src,u<<,inf);
}
while(bfs())
ans+=dinic(src,inf);
printf("%d",ans);
}
洛谷2944 [USACO09MAR]地震损失2Earthquake Damage 2的更多相关文章
- P2944 [USACO09MAR]地震损失2Earthquake Damage 2(网络流)
P2944 [USACO09MAR]地震损失2Earthquake Damage 2 $P$个点,$C$条双向边.求最少删去几个点使$N$个给定的点与点$1$分开. 显然的最小割. 将点$i$套路地拆 ...
- [USACO09MAR]地震损失2Earthquake Damage 2
地震破坏 时间限制: 1 Sec 内存限制: 128 MB 题目描述 威斯康星发生了一场地震!约翰的牧场遭到了打击,有一些牛棚变成了废墟,如果一间牛棚遭到 了破坏,那么所有和它相连的道路都不能使用了 ...
- p2944 [USACO09MAR]地震损失2Earthquake Damage 2
传送门 分析 我们让s到1,关键点到t分别连流量为inf的边 于是我们可以考虑跑s到t的最小割 于是我们将所有点拆为两个点,关键点和1的两个点之间连inf,其余点连1 将原图的边也连上,流量为inf ...
- 洛谷P2947 [USACO09MAR]仰望Look Up
P2947 [USACO09MAR]仰望Look Up 74通过 122提交 题目提供者洛谷OnlineJudge 标签USACO2009云端 难度普及/提高- 时空限制1s / 128MB 提交 ...
- 洛谷 P2932 [USACO09JAN]地震造成的破坏Earthquake Damage
P2932 [USACO09JAN]地震造成的破坏Earthquake Damage 题目描述 Wisconsin has had an earthquake that has struck Farm ...
- 「洛谷P1343」地震逃生 解题报告
P1343 地震逃生 题目描述 汶川地震发生时,四川XX中学正在上课,一看地震发生,老师们立刻带领x名学生逃跑,整个学校可以抽象地看成一个有向图,图中有n个点,m条边.1号点为教室,n号点为安全地带, ...
- 洛谷 P2945 [USACO09MAR]沙堡Sand Castle 题解
题目传送门 大概思路就是把这两个数组排序.在扫描一次,判断大小,累加ans. #include<bits/stdc++.h> using namespace std; int x,y,z; ...
- 洛谷 P2947 [USACO09MAR]向右看齐Look Up【单调栈】
题目描述 Farmer John's N (1 <= N <= 100,000) cows, conveniently numbered 1..N, are once again stan ...
- 洛谷 P2945 [USACO09MAR]沙堡Sand Castle
传送门 题目大意: ai,ai+1,ai+2... 变成 bi,bi+1,bi+2.. 不计顺序,增加和减少a数组均有代价. 题解:贪心+排序 小的对应小的 代码: #include<iostr ...
随机推荐
- Python高级编程-多线程
(一)进程线程概述: 很多同学都听说过,现代操作系统比如Mac OS X,UNIX,Linux,Windows等,都是支持“多任务”的操作系统. 什么叫“多任务”呢?简单地说,就是操作系统可以同时运行 ...
- 2019寒假训练营第三次作业part1-网络空间安全概论第五章
第五章 网络攻防技术 5.1 网路信息收集技术--网络踩点 黑客入侵系统之前,需要了解目标系统可能存在的: 管理上的安全缺陷和漏洞 网络协议安全缺陷与漏洞 系统安全缺陷与漏洞 黑客实施入侵过程中,需要 ...
- P4编程环境搭建遇到的问题与解决方法
在经历了无数的折腾之后,算是折腾,最后采用的是陈翔学长的脚本加上可爱的shell调整装好的. 链接:p4Install 也许是ubuntu18.04的问题,也有可能是我自己把这个系统折腾的有点杂乱的原 ...
- PokeCats开发者日志(十)
现在是PokeCats游戏开发的第三十三天的中午,收到了中国版权保护中心软件登记部发来的受理通知书. 上易版权看一眼,貌似离拿证不远了. 想一想还有点小激动呢!
- tweenjs缓动算法使用小实例
这里的tweenjs不是依托于createjs的tewwnjs,而是一系列缓动算法集合.因为本身是算法,可以用在各个业务场景中,这也正是总结学习它的价值所在.tweenjs代码详情: /* * Twe ...
- windows批处理学习(for和字符串)---03
[1]for命令简介 先把for循环与for命令类比一下,这样学习理解快. for 循环语句,一般格式如下: 1 for (表达式1;表达式2;表达式3) 2 { 3 循环体; 4 } 1. 表达式1 ...
- Winform 数据绑定
1.DataGridView数据绑定 namespace WindowsFormsApplication1 { public partial class Form1 : Form { private ...
- ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction 表被锁的解决办法
转自:https://blog.csdn.net/mchdba/article/details/38313881 前言:朋友咨询我说执行简单的update语句失效,症状如下:mysql> upd ...
- SpringBoot2.0(二) 配置文件多环境
在SpringBoot中,多环节的配置文件名基于application-{profile}.properties的格式,其中{profile}对应环境标识,比如: application-daily. ...
- springBoot按条件装配:Condition
编码格式转换器接口 package com.boot.condition.bootconditionconfig.converter; /** * 编码格式转换器接口 */ public interf ...