洛谷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 ...
随机推荐
- HTMLTestRunner解决UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xe5 in position 108: ordinal not in range(128)
其中HTML和数据库都是设置成utf-8格式编码,插入到数据库中是正确的,但是当读取出来的时候就会出错,原因就是python的str默认是ascii编码,和unicode编码冲突,就会报这个标题错误. ...
- vue学习笔记之:为何data是一个方法
vue学习笔记之:为何data是一个方法 在vue开发中,我们可以发现,data中的属性值是在function中return出来的.可为何data必须是一个函数呢?我们先看官方的解释: 当一个组件被定 ...
- c# 两个软件传参
1.socket 传参,类似于小型的服务器和客户端,一端发送,另一端保持监听状态. 2.通过第三方 数据库或者文件.
- 搭建独立域名博客 -- 独立域名博客上线了 www.hanshuliang.com
博客是安装在阿里云的服务器上. 小结 : -- 进入数据库命令 :mysql -uroot -p123456 ; -- 检查nginx配置语法 :.../nginx/sbin/nginx -t; -- ...
- 软工实践-Alpha 冲刺 (1/10)
队名:起床一起肝活队 组长博客:博客链接 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 过去两天完成了哪些任务 描述: 学习了UI设计软件的使用,了解了项目开发的具体流程. 展示 ...
- Linux的ll命令详解
ll 列出来的结果详细,有时间,是否可读写等信息 ,象windows里的 详细信息 ls 只列出文件名或目录名 就象windows里的 列表 ll -t 是降序, ll -t | tac 是升序 l ...
- LintCode-69.二叉树的层次遍历
二叉树的层次遍历 给出一棵二叉树,返回其节点值的层次遍历(逐层从左往右访问) 样例 给一棵二叉树 {3,9,20,#,#,15,7} : 返回他的分层遍历结果: [ [3], [9,2 ...
- css那些事儿4 背景图像
background:背景颜色,图像,平铺方式,大小,位置 能够显示背景区域即为盒子模型的填充和内容部分,其中背景图像将会覆盖背景颜色.常见的水平或垂直渐变颜色背景通常使用水平或垂直渐变的背景图像在水 ...
- AWVS使用基础教程
什么是AWVS Acunetix Web Vulnerability Scanner(简称AWVS)是一款知名的网络漏洞扫描工具,它通过网络爬虫测试你的网站安全,检测流行安全漏洞,现已更新到10.(下 ...
- Windows Sever 2008隐藏和系统属性
由于有些目录为隐藏和系统属性,首先要把 显示系统文件和显示所有文件 功能开启,把隐藏文件和目录显出来. 1.C:\Windows\Web\Wall*** 自带墙纸,不需要的可以删除掉. 2.C:\Wi ...