[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 ...
随机推荐
- JS日历控件 灵活设置: 精确的时分秒.
在今年7月份时候 写了一篇关于 "JS日历控件" 的文章 , 当时仅仅支持 年月日 的日历控件,如今优化例如以下: 1. 在原基础上 支持 yyyy-mm-dd 的年月 ...
- iOS 浅谈MVC设计模式及Controllers之间的传值方式
1.简述你对MVC的理解? MVC是一种架构设计.它考虑了三种对象:Model(模型对象).View(试图对象).Controller(试图控制器) (1)模型:负责存储.定义.操作数据 (2)视图: ...
- 【iOS系列】-iOS查看沙盒文件图文教程(真机+模拟器)
[iOS系列]-iOS查看沙盒文件图文教程(真机+模拟器) 1:模拟器 1.1 方法1: 程序中打印一下的地址,能直接前往沙盒路径. NSString *path = [NSSearchPathFor ...
- Chart.js docs
原文链接:http://www.bootcss.com/p/chart.js/docs/ 引入Chart.js文件 首先我们需要在页面中引入Chart.js文件.此工具库在全局命名空间中定义了Char ...
- YTU 2928: 取不重复的子串。
2928: 取不重复的子串. 时间限制: 1 Sec 内存限制: 128 MB 提交: 5 解决: 5 题目描述 输入字母构成的字符串(不大于30字符)从中读取3个不重复的字符,求所有取法,取出的 ...
- Resolve the error: an error occurred during local report processing
Issue: an error occurred during local report processing.the definition of the report'Main Report'is ...
- hdu 3507(DP+斜率优化)
Print Article Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)To ...
- 小程序-demo:小程序示例-page/api
ylbtech-小程序-demo:小程序示例-page/api 以下将演示小程序接口能力,具体属性参数详见小程序开发文档. 1. page/component返回顶部 1. a) .js Page({ ...
- redis info 参数说明
原文: redis info 参数说明 redis 127.0.0.1:6381> info redis_version:2.4.16 # Redis 的版本redis_git_sha1:000 ...
- 虚拟机C盘扩容
使用 <分区助手> 下载地址:http://115.com/file/belj8wkm