p2944 [USACO09MAR]地震损失2Earthquake Damage 2
分析
我们让s到1,关键点到t分别连流量为inf的边
于是我们可以考虑跑s到t的最小割
于是我们将所有点拆为两个点,关键点和1的两个点之间连inf,其余点连1
将原图的边也连上,流量为inf
于是跑最小割即可
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
const int dx[] = {,-,,};
const int dy[] = {,,,-};
const int inf = 1e9+;
int n,m,s,t,head[],to[],nxt[],w[],ano[],cnt,level[],cur[];
int used[];
inline void add(int x,int y,int z){
nxt[++cnt]=head[x];
head[x]=cnt;
to[cnt]=y;
w[cnt]=z;
ano[cnt]=cnt+;
nxt[++cnt]=head[y];
head[y]=cnt;
to[cnt]=x;
w[cnt]=;
ano[cnt]=cnt-;
}
inline bool bfs(){
memset(level,-,sizeof(level));
queue<int>q;
level[s]=;
q.push(s);
while(!q.empty()){
int x=q.front();
q.pop();
for(int i=head[x];i;i=nxt[i])
if(level[to[i]]==-&&w[i]){
level[to[i]]=level[x]+;
if(to[i]==t)return ;
q.push(to[i]);
}
}
return ;
}
inline int dfs(int x,int flow){
if(x==t||!flow)return flow;
int res=;
cur[x]=head[x];
for(int i=cur[x];i;i=nxt[i]){
cur[x]=i;
if(level[to[i]]==level[x]+&&w[i]){
int f=dfs(to[i],min(w[i],flow-res));
w[i]-=f;
res+=f;
w[ano[i]]+=f;
}
}
if(!res)level[x]=-;
return res;
}
int main(){
int i,j,k,Ans=;
scanf("%d%d%d",&n,&m,&k);
s=*n+,t=s+;
add(s,,inf);
add(,n+,inf);
for(i=;i<=m;i++){
int x,y;
scanf("%d%d",&x,&y);
add(x+n,y,inf);
add(y+n,x,inf);
}
for(i=;i<=k;i++){
int x;
scanf("%d",&x);
add(x+n,t,inf);
add(x,x+n,inf);
used[x]=;
}
for(i=;i<=n;i++){
if(used[i])continue;
add(i,i+n,);
}
while(bfs())while(int a=dfs(s,inf))Ans+=a;
cout<<Ans;
return ;
}
p2944 [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 题目描述 威斯康星发生了一场地震!约翰的牧场遭到了打击,有一些牛棚变成了废墟,如果一间牛棚遭到 了破坏,那么所有和它相连的道路都不能使用了 ...
- 洛谷2944 [USACO09MAR]地震损失2Earthquake Damage 2
https://www.luogu.org/problem/show?pid=2944 题目描述 Wisconsin has had an earthquake that has struck Far ...
- 【P2944】地震损失(最大流,洛谷)
绝对难度虚高的一题 看到题目,至少损坏几个房子,开始考虑最小割,建的是双向边,所以拆点,边权除了自己与自己的之外都连inf.然后把所有求救的点都连到超级源上,跑一遍最大流就可以了. #include& ...
- 【BZOJ1585】【Luogu2944】地震损失2(网络流)
[BZOJ1585][Luogu2944]地震损失2(网络流) 题面 题目描述 Wisconsin has had an earthquake that has struck Farmer John' ...
- 1574: [Usaco2009 Jan]地震损坏Damage
1574: [Usaco2009 Jan]地震损坏Damage Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 425 Solved: 232[Subm ...
- bzoj 1585: [Usaco2009 Mar]Earthquake Damage 2 地震伤害
1585: [Usaco2009 Mar]Earthquake Damage 2 地震伤害 Description Farmer John的农场里有P个牧场,有C条无向道路连接着他们,第i条道路连接着 ...
- 洛谷 P2932 [USACO09JAN]地震造成的破坏Earthquake Damage
P2932 [USACO09JAN]地震造成的破坏Earthquake Damage 题目描述 Wisconsin has had an earthquake that has struck Farm ...
- BZOJ 1574: [Usaco2009 Jan]地震损坏Damage
Description 农夫John的农场遭受了一场地震.有一些牛棚遭到了损坏,但幸运地,所有牛棚间的路经都还能使用. FJ的农场有P(1 <= P <= 30,000)个牛棚,编号1.. ...
随机推荐
- 在 myeclipse中进行连接sql server的测试
在 myeclipse中,连接 sql server 用的 url connection 与 java 代码 连接的 url值完全相同. (一下为 java的jdbc连接 sql server 成功的 ...
- Synergy CORTEX M 启动流程
1.启动文件“startup_S7G2.c” 中断向量表地址指针:“0xe000ed08” /* Vector table. */ BSP_DONT_REMOVE const exc_ptr_t __ ...
- couchdb的使用例子
couchdb安装 sudo apt-get install erlang sudo apt-get install libmozjs185-dev libicu-dev 下载源码,编译安装 启动以后 ...
- 分布式事务之:TCC (Try-Confirm-Cancel) 模式
在当前如火如荼的互联网浪潮下,如何应对海量数据.高并发成为大家面临的普遍难题.广大IT公司从以往的集中式网站架构,纷纷转向分布式的网站架构,随之而来的就是进行数据库拆分和应用拆分,如何在跨数据库.跨应 ...
- Thread.setDaemon详解
Thread.setDaemon详解 线程分为两种类型:用户线程和守护线程.通过Thread.setDaemon(false)设置为用户线程:通过Thread.setDaemon(true)设置为守护 ...
- centos如何使用utc时间
1.将本地时间文件改名,做备份文件为localtime2 mv /etc/localtime /etc/localtime2 2.将UTC文件和本地文件做连接ln -s /usr/share/zone ...
- python学习 (三十三) Modules
1: 方法一: 导入整个模块 import math class ModulesDemo(): def builtin_modules(self): print(math.sqrt()) m = Mo ...
- Hibernate 一对一、一对多、多对多注解cascade属性的总结
作用:是否级联被注解字段里面的对象.可选值:javax.persistence.CascadeType.PERSIST, MERGE, REMOVE, REFRESH, DETACH, ALL.可选其 ...
- oracle系统表v$session、v$sql字段说明(转)
在本视图中,每一个连接到数据库实例中的 session都拥有一条记录.包括用户 session及后台进程如 DBWR, LGWR, arcchiver等等. V$SESSION中的常用列 V$SESS ...
- Linux 之rsyslog+LogAnalyzer 日志收集系统
一.LogAnalyzer介绍 LogAnalyzer工具提供了一个易于使用,功能强大的前端,用于搜索,查看和分析网络活动数据,包括系统日志,事件日志和其他许多日志源.由于它只是将数据展示到我们用户的 ...