[Luogu1345][USACO5.4]Telecowmunication 最大流
题目链接:https://www.luogu.org/problem/show?pid=1345
求最小割点集的大小,直接拆点转化成最小割边。把一个点拆成出点入点,入点向出点连一条容量为1的边,其他的边容量无穷大。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int INF=<<;
int inline readint(){
int Num;char ch;
while((ch=getchar())<''||ch>'');Num=ch-'';
while((ch=getchar())>=''&&ch<='') Num=Num*+ch-'';
return Num;
}
int N,M,S,T;
int to[],ne[],c[],fir[],cnt=;
void Add(int x,int y,int z){
to[cnt]=y;
c[cnt]=z;
ne[cnt]=fir[x];
fir[x]=cnt++;
to[cnt]=x;
c[cnt]=;
ne[cnt]=fir[y];
fir[y]=cnt++;
}
int dep[],bfn[],ti=;
int q[],head,tail;
bool Bfs(){
head=tail=;
q[]=S;
dep[S]=;
bfn[S]=++ti;
while(head<=tail){
int u=q[head++];
for(int i=fir[u];i!=-;i=ne[i]){
int v=to[i];
if(bfn[v]!=ti&&c[i]){
bfn[v]=ti;
dep[v]=dep[u]+;
q[++tail]=v;
}
}
}
return bfn[T]==ti;
}
int cur[];
int Dfs(int u,int maxf){
if(u==T||!maxf) return maxf;
int flow=,f;
for(int &i=cur[u];i!=-;i=ne[i]){
int v=to[i];
if(dep[v]==dep[u]+&&(f=Dfs(v,min(maxf,c[i])))>){
flow+=f,maxf-=f;
c[i]-=f,c[i^]+=f;
if(!maxf) break;
}
}
return flow;
}
int Dinic(){
int ans=;
while(Bfs()){
memcpy(cur,fir,sizeof(fir));
ans+=Dfs(S,INF);
}
return ans;
}
int main(){
N=readint();
M=readint();
S=readint();
T=readint();
memset(fir,-,sizeof(fir));
for(int i=;i<=M;i++){
int a=readint(),
b=readint();
Add(a+N,b,INF);
Add(b+N,a,INF);
}
for(int i=;i<=N;i++) Add(i,i+N,);
Add(S,S+N,INF);
printf("%d\n",Dinic());
return ;
}
[Luogu1345][USACO5.4]Telecowmunication 最大流的更多相关文章
- luogu1345 [USACO5.4]奶牛的电信Telecowmunication
对于每个点,把它拆成有权值为1的边相连的两个点,原边是inf. 边的起点统一加n,ss也加n 这就成了最小割 #include <iostream> #include <cstrin ...
- USACO 5.4 Telecowmunication(最大流+枚举)
面对最小割之类的题目,完全木想法... 枚举+最大流..复杂度很大了...居然很快的就过了.. /* ID: cuizhe LANG: C++ TASK: telecow */ #include &l ...
- P1345 [USACO5.4]奶牛的电信Telecowmunication【最小割】【最大流】
题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮:如果存在一个由c台电脑组成的序列a1,a2,...,a(c),且a1与a2相 ...
- P1345 [USACO5.4]奶牛的电信Telecowmunication
P1345 [USACO5.4]奶牛的电信Telecowmunication 题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮 ...
- 洛谷——P1345 [USACO5.4]奶牛的电信Telecowmunication
P1345 [USACO5.4]奶牛的电信Telecowmunication 题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮 ...
- 题解 P1345 【[USACO5.4]奶牛的电信Telecowmunication】
P1345 [USACO5.4]奶牛的电信Telecowmunication 题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮 ...
- [Luogu P1345] [USACO5.4]奶牛的电信Telecowmunication (最小割)
题面 传送门:https://www.luogu.org/problemnew/show/P1345 ] Solution 这道题,需要一个小技巧了解决. 我相信很多像我这样接蒟蒻,看到这道题,不禁兴 ...
- 洛谷P1345 [USACO5.4]奶牛的电信Telecowmunication【最小割】分析+题解代码
洛谷P1345 [USACO5.4]奶牛的电信Telecowmunication[最小割]分析+题解代码 题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流. ...
- AC日记——[USACO5.4]奶牛的电信Telecowmunication 洛谷 P1345
[USACO5.4]奶牛的电信Telecowmunication 思路: 水题: 代码: #include <cstdio> #include <cstring> #inclu ...
随机推荐
- [CSAPP]Bufbomb实验报告
Bufbomb实验报告 实验分析: level 0-3从test開始制运行,通过函数getbuf向外界读取一串内容(buf). Level 4 是通过參数-n,程序运行testn函数,调用getbuf ...
- IOS报错:Unexpected ‘@’ in program
IOS开发中出现此错误的原因: 1.宏定义重复. 我在OC与C++混编的时候,由于C++中使用到了interface,在工程中年将interface从定义为struct,当引用此接口时候出现Unexp ...
- 【Linux 内核网络协议栈源码剖析】网络栈主要结构介绍(socket、sock、sk_buff,etc)
原文:http://blog.csdn.net/wenqian1991/article/details/46700177 通过前面的分析,可以发现,网络协议栈中的数据处理,都是基于各类结构体,所有有关 ...
- HDU1069 Monkey and Banana —— DP
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1069 Monkey and Banana Time Limit: 2000/1000 MS ...
- Maven运行测试
原文:http://tianya23.blog.51cto.com/1081650/292315/ Maven运行用于测试中的最佳实践(个人认为,呵呵) 1.创建maven工程 mvn arche ...
- mac toad下建表问题
mac toad下创建表,表名会自动多一个双引号,如:tb_test => "tb_test",这个应该是mac系统智能引号问题导致的,目前还没找到解决办法,只能手动用sql ...
- BZOJ4561:圆的异或并(扫描线+set||splay||线段树)
在平面直角坐标系中给定N个圆.已知这些圆两两没有交点,即两圆的关系只存在相离和包含.求这些圆的异或面 积并.异或面积并为:当一片区域在奇数个圆内则计算其面积,当一片区域在偶数个圆内则不考虑. I ...
- Ubuntu 14.04.1 配置 Android 源码开发环境(jdk版本切换)(转载)
转自:http://www.cnblogs.com/ren-gh/p/4248407.html # Ubuntu 14.04.1 1.更新源: sudo apt-get update 安装vim工具: ...
- bzoj 1103: [POI2007]大都市meg【dfs序+树状数组】
很明显的暗示,就是在树的dfs序上维护树状数组,加减的时候差分即可 #include<iostream> #include<cstdio> #include<cstrin ...
- bzoj 4184: shallot【线性基+时间线段树】
学到了线段树新姿势! 先离线读入,根据时间建一棵线段树,每个节点上开一个vector存这个区间内存在的数(使用map来记录每个数出现的一段时间),然后在线段树上dfs,到叶子节点就计算答案. 注意!! ...