洛谷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 ...
随机推荐
- POJ 1739 Tony's Tour(插头DP)
Description A square township has been divided up into n*m(n rows and m columns) square plots (1< ...
- ZOJ 3644 Kitty's Game(数论+DP)
Description Kitty is a little cat. She is crazy about a game recently. There arenscenes in the game( ...
- 词频统计 SPEC 20170914 1 1 1 1 1
功能1 小文件输入,为表明程序能跑,结果真实而不是迫害老五,请他亲自键盘在控制台下输入命令. #include<stdio.h> #include<string.h> #inc ...
- Android 网络编程 API笔记 - java.net 包 权限 地址 套接字 相关类 简介
Android 网络编程相关的包 : 9 包, 20 接口, 103 类, 6 枚举, 14异常; -- Java包 : java.net 包 (6接口, 34类, 2枚举, 12异常); -- An ...
- TCP源码—系统调用
1.socket SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol) sys_socket->sock_create-& ...
- 3dContactPointAnnotationTool开发日志(八)
今天上午去实验室打算把项目从github上pull下来发现貌似不行,然后强行pull下来后项目变得乱七八糟了,有的组件都不知道去哪里了.去github上看了看发现上面day6和day7都没有,特别 ...
- cacti设置redis监控端口
1.在Console->Data Templates中选择Redis的模版 在custom Data中勾选中Port2并保存 2.在Console->Data Input Methods中 ...
- do_group_exit函数
一个进程在sleep状态如何获取进程的调用栈 TASK_WAKEUPKILL状态 一个进程sleep了,我如何获取他的用户态栈,如何获取用户堆栈 如何在内核态打印用户态+内核态的栈? 确定上一个调用栈 ...
- centos7编译安装redis遇坑
编译redis时:make cc Command not found 原因分析:没有安装gcc,执行: yum install gcc 编译redis时:error: jemalloc/jemallo ...
- Delphi处理事件函数中的Sender: TObject代表什么?
下面这个按钮点击事件中,Sender代表谁? procedure Tsomain.ToolButton1Click(Sender: TObject); 是代表事件的拥有者吗? procedure TF ...