bzoj 1797: [Ahoi2009]Mincut 最小割 (网络流)
太神了直接看了hzwer的题解,有个新认识,一条路径上满流的一定是这条路径上所有边的最小值。
typearr=recordtoward,next,cap,from:longint;end; constmaxm=200000;maxn=10000; varedge:array[0..maxm]of arr;first,cur,d,p,gap:array[0..maxn]of longint;chose1,chose2:array[0..maxn]of boolean;n,m,s,t,tot,esum:longint;function min(x,y:longint):longint; beginif x<y then exit(x);exit(y); end;procedure add(j,k,l:longint); begininc(esum);edge[esum].from:=j;edge[esum].toward:=k;edge[esum].next:=first[j];first[j]:=esum;edge[esum].cap:=l; end;procedure addedge(j,k,l:longint); beginadd(j,k,l);add(k,j,0); end;function sap(x,flow:longint):longint; varnow,more,i,too:longint; beginif x=t then exit(flow);now:=0;i:=cur[x];while i>=0 do begintoo:=edge[i].toward;if (d[x]=d[too]+1) and (edge[i].cap>0) then beginmore:=sap(too,min(flow-now,edge[i].cap));dec(edge[i].cap,more);inc(edge[i xor 1].cap,more);inc(now,more);cur[x]:=i;if now=flow then exit(flow);end;i:=edge[i].next;end;dec(gap[d[x]]);if gap[d[x]]=0 then d[s]:=n;inc(d[x]);inc(gap[d[x]]);cur[x]:=first[x];exit(now); end;procedure maxflow; vari:longint; beginfillchar(d,sizeof(d),0);fillchar(gap,sizeof(gap),0);gap[0]:=n;for i:=1 to n do cur[i]:=first[i];while d[s]<n do sap(s,maxlongint); end;procedure into; vari,j,k,l:longint; beginesum:=-1;fillchar(first,sizeof(first),255);readln(n,m,s,t);for i:=1 to m do beginreadln(j,k,l);addedge(j,k,l);end; end;procedure work; varhead,tail,x,y,i,j,too:longint; beginmaxflow;{ for i:=0 to m<<1 dowriteln(edge[i].from,' ',edge[i].toward,' ',edge[i].next,' ',edge[i].cap); }head:=1;tail:=1;p[1]:=s;fillchar(chose1,sizeof(chose1),false);chose1[s]:=true;while head<=tail do beginx:=p[head];i:=first[x];while i>=0 do begintoo:=edge[i].toward;if (edge[i].cap>0) and (not chose1[too]) then begininc(tail);p[tail]:=too;chose1[too]:=true;end;i:=edge[i].next;end;inc(head);end;//for i:=1 to n do writeln(i,' ',chose1[i]);head:=1;tail:=1;p[1]:=t;fillchar(chose2,sizeof(chose2),false);chose2[t]:=true;while head<=tail do beginx:=p[head];i:=first[x];while i>=0 do begintoo:=edge[i].toward;if (edge[i xor 1].cap>0) and (not chose2[too]) then begininc(tail);p[tail]:=too;chose2[too]:=true;end;i:=edge[i].next;end;inc(head);end;//for i:=1 to n do writeln(i,' ',chose2[i]);for i:=1 to m do beginj:=(i-1)<<1;if edge[j].cap>0 then beginwriteln(0,' ',0);continue;end;x:=edge[j].from;y:=edge[j].toward;if not ( (chose1[x] and chose1[y]) or (chose2[x] and chose2[y]) )then write(1) else write(0);write(' ');if (chose1[x] and chose2[y]) or (chose1[y] and chose2[x])then writeln(1) else writeln(0);end;readln; end;begininto;work; end.
View Code
转载于:https://www.cnblogs.com/Macaulish/p/4358173.html
bzoj 1797: [Ahoi2009]Mincut 最小割 (网络流)相关推荐
- 边与最小割(bzoj 1797: [Ahoi2009]Mincut 最小割)
1797: [Ahoi2009]Mincut 最小割 Time Limit: 10 Sec Memory Limit: 162 MB Submit: 2471 Solved: 1067 [Subm ...
- [bzoj1797][Ahoi2009]Mincut 最小割
来自FallDream的博客,未经允许,请勿转载,谢谢qaq A,B两个国家正在交战,其中A国的物资运输网中有N个中转站,M条单向道路.设其中第i (1≤i≤M)条道路连接了vi,ui两个中转站,那么 ...
- P4126 [AHOI2009]最小割(网络流/最小割)
P4126 [AHOI2009]最小割 https://www.cnblogs.com/dugudashen/p/6228304.html 求解一张有向图中关于最小割的可行边和必须边,可行边定义为存在 ...
- BZOJ 2039 人员雇佣 (最小割)
题面:BZOJ传送门 网络流的题真神仙= = 大致分为三种情况 选某个人$i$,收益减少$a_{i}$ 选了$i$选了$j$,收益增加$2e_{ij}$ 选了$i$不选$j$,收益减少$e_{ij}$ ...
- BZOJ.2521.[SHOI2010]最小生成树(最小割ISAP/Dinic)
题目链接 一条边不变其它边减少可以看做一条边增加其它边不变. 假设要加的边lab为(A->B,v),那么肯定是要使除这条边外,A->B的每条路径上的最小权值都\(>v\),这样在连通 ...
- bzoj 2007 [Noi2010]海拔——最小割转最短路
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2007 一个点的高度一定不是0就是1.答案一定形如一个左上角的连通块全是0的点.一个右下角的连 ...
- BZOJ.3144.[HNOI2013]切糕(最小割)
题目链接 没有\(D\)的限制怎么做?"最小"我们可以想到最小割,把同一纵轴上的点串起来,分别连到S,T,最小割就是答案.(在这把点权放到前一条边上) 有限制,即如果要割点\(i\ ...
- bzoj 3894: 文理分科 最小割
Description 文理分科是一件很纠结的事情!(虽然看到这个题目的人肯定都没有纠 结过) 小P所在的班级要进行文理分科.他的班级可以用一个n*m的矩阵进行 描述,每个格子代表一个同学的座位.每位 ...
- BZOJ 3894 文理分科 最小割
题目大意:给定一个m*n的矩阵,每个格子的人可以学文或者学理,学文和学理各有一个满意度,如果以某人为中心的十字内所有人都学文或者学理还会得到一个额外满意度,求最大满意度之和 令S集为学文,T集为学理 ...
最新文章
- 用批处理查询电脑信息
- asp.net 在 Ngnix 服务器 中配置攻略
- Python字典排序sorted无效,用匿名函数lambda解决
- CentOS Linux 下的 vim 无法使用系统剪贴板,怎么解决呢?
- hdu 4738 Caocao's Bridges 求无向图的桥【Tarjan】
- Spring:笔记整理(1)——HelloWorld
- 如何做相册_今天才知道,原来长按微信相册,还隐藏着一个实用功能
- 理解 Hook 规则
- mac mysql配置jdk_mac开发环境搭建
- C#读取 *.exe.config
- jsp中你必须记住的379
- java 计算税收_根据税收征收管理法律制度的规定,整个税收征收管理的起点是( )...
- ie上直接打开服务器word文档,win7 ie11直接打开word
- Excel:如何批量将文本数字转为数值型数据
- 【檀越剑指大厂--ElasticSearch】ElasticSearch进阶
- mysql中null值求和_sql求和涉及到null值
- .tar.lz压缩包解压
- 管理后台 - 轮播图片管理功能
- JavaScript三种注释写法
- 前后端传输加密代码-java