AHOI2009最小割
1797: [Ahoi2009]Mincut 最小割
Time Limit: 10 Sec Memory Limit: 162 MB
Submit: 1072 Solved: 446
[Submit][Status]
Description
Input
Output
Sample Input
1 2 3
1 3 2
2 4 4
2 5 1
3 5 5
4 6 2
5 6 3
Sample Output
1 0
0 0
1 0
0 0
1 0
1 0
HINT
设第(i+1)行输入的边为i号边,那么{1,2},{6,7},{2,4,6}是仅有的三个最小代价切割方案。它们的并是{1,2,4,6,7},交是 。
【数据规模和约定】
测试数据规模如下表所示
数据编号 N M 数据编号 N M
1 10 50 6 1000 20000
2 20 200 7 1000 40000
3 200 2000 8 2000 50000
4 200 2000 9 3000 60000
5 1000 20000 10 4000 60000
Source
题解:摘自jcvb
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
一个有向图,源点s,汇点t,问哪些边能够出现在某个最小割集中,哪些边必定出现在最小割集中。
求最大流,在残余网络上跑tarjan求出所有SCC,记id[u]为点u所在SCC的编号。显然有id[s]!=id[t](否则s到t有通路,能继续增广)。
①对于任意一条满流边(u,v),(u,v)能够出现在某个最小割集中,当且仅当id[u]!=id[v];
②对于任意一条满流边(u,v),(u,v)必定出现在最小割集中,当且仅当id[u]==id[s]且id[v]==id[t]。
简要写一下证明:
首先,由最大流最小割定理易知最小割中的割边一定是满流边。
①
==>如果id[u]==id[v],则残余网络存在u->v的通路,通过(u,v)的割也必然通过这条通路上的某条非满流边,不会是最小割。(update:QAQ后来发现这个证明有问题。。。到时候再想想)
<==将每个SCC缩成一个点,得到的新图就只含有满流边了。那么新图的任一s-t割都对应原图的某个最小割,从中任取一个把id[u]和id[v]割开的割即可证明。
②
<==:假设将(u,v)的边权增大,那么残余网络中会出现s->u->v->t的通路,从而能继续增广,于是最大流流量(也就是最小割容量)会增大。这即说明(u,v)是最小割集中必须出现的边。
==>:上面的证明可以反推回去,略。
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
结论是正确的,可以AC
代码:
const inf=maxlongint;
type node=record
from,go,next,v:longint;
end;
var tot,i,j,n,m,maxflow,l,r,s,t,x,y,z,ti,top,cnt,xx,yy:longint;
h,head,q,cur,low,dfn,sta,scc:array[..] of longint;
e:array[..] of node;
function min(x,y:longint):longint;
begin
if x<y then exit(x) else exit(y);
end;
procedure ins(x,y,z:longint);
begin
inc(tot);
e[tot].from:=x;e[tot].go:=y;e[tot].v:=z;e[tot].next:=head[x];head[x]:=tot;
end;
procedure insert(x,y,z:longint);
begin
ins(x,y,z);ins(y,x,);
end;
function bfs:boolean;
var i,x,y:longint;
begin
fillchar(h,sizeof(h),);
l:=;r:=;q[]:=s;h[s]:=;
while l<r do
begin
inc(l);
x:=q[l];
i:=head[x];
while i<> do
begin
y:=e[i].go;
if (e[i].v<>) and (h[y]=) then
begin
h[y]:=h[x]+;
inc(r);q[r]:=y;
end;
i:=e[i].next;
end;
end;
exit (h[t]<>);
end;
function dfs(x,f:longint):longint;
var i,y,used,tmp:longint;
begin
if x=t then exit(f);
used:=;
i:=cur[x];
while i<> do
begin
y:=e[i].go;
if (h[y]=h[x]+) and (e[i].v<>) then
begin
tmp:=dfs(y,min(e[i].v,f-used));
dec(e[i].v,tmp);if e[i].v<> then cur[x]:=i;
inc(e[i xor ].v,tmp);
inc(used,tmp);
if used=f then exit(f);
end;
i:=e[i].next;
end;
if used= then h[x]:=-;
exit(used);
end;
procedure dinic;
begin
while bfs do
begin
for i:= to n do cur[i]:=head[i];
inc(maxflow,dfs(s,inf));
end;
end;
procedure init;
begin
tot:=;
readln(n,m,s,t);
for i:= to m do
begin
readln(x,y,z);
insert(x,y,z);
end;
end;
procedure dfs(x:longint);
var i,y,z:longint;
begin
inc(ti);dfn[x]:=ti;low[x]:=ti;inc(top);sta[top]:=x;
i:=head[x];
while i<> do
begin
y:=e[i].go;
if e[i].v<> then
begin
if dfn[y]= then
begin
dfs(y);
low[x]:=min(low[x],low[y]);
end
else if scc[y]= then low[x]:=min(low[x],dfn[y]);
end;
i:=e[i].next;
end;
if low[x]=dfn[x] then
begin
inc(cnt);
while true do
begin
z:=sta[top];dec(top);
scc[z]:=cnt;
if z=x then break;
end;
end;
end;
procedure tarjan;
begin
ti:=;cnt:=;ti:=;
fillchar(dfn,sizeof(dfn),);
for i:= to n do if dfn[i]= then dfs(i);
end;
procedure main;
begin
dinic;
tarjan;
x:=scc[s];y:=scc[t];
for i:= to tot do
if (i and =) then
begin
if e[i].v<> then begin writeln('0 0');continue;end;
xx:=scc[e[i].from];yy:=scc[e[i].go];
if xx<>yy then write('') else write('');write(' ');
if (xx=x) and (yy=y) then write('') else write('');
writeln;
end;
end;
begin
assign(input,'input.txt');assign(output,'output.txt');
reset(input);rewrite(output);
init;
main;
close(input);close(output);
end.
AHOI2009最小割的更多相关文章
- P4126 [AHOI2009]最小割
题目地址:P4126 [AHOI2009]最小割 最小割的可行边与必须边 首先求最大流,那么最小割的可行边与必须边都必须是满流. 可行边:在残量网络中不存在 \(x\) 到 \(y\) 的路径(强连通 ...
- 【BZOJ1797】[AHOI2009]最小割(网络流)
[BZOJ1797][AHOI2009]最小割(网络流) 题面 BZOJ 洛谷 题解 最小割的判定问题,这里就当做记结论吧.(源自\(lun\)的课件) 我们先跑一遍最小割,求出残量网络.然后把所有还 ...
- P4126 [AHOI2009]最小割(网络流+tarjan)
P4126 [AHOI2009]最小割 边$(x,y)$是可行流的条件: 1.满流:2.残量网络中$x,y$不连通 边$(x,y)$是必须流的条件: 1.满流:2.残量网络中$x,S$与$y,T$分别 ...
- 洛谷P4126 [AHOI2009]最小割
题目:洛谷P4126 [AHOI2009]最小割 思路: 结论题 在残余网络上跑tarjan求出所有SCC,记id[u]为点u所在SCC的编号.显然有id[s]!=id[t](否则s到t有通路,能继续 ...
- [AHOI2009]最小割
题目 最小割的可行边和必须边 可行边\((u,v)\)需要满足以下两个条件 满流 残量网络中不存在\(u\)到\(v\)的路径 这个挺好理解的呀,如果存在还存在路径的话那么这条边就不会是瓶颈了 必须边 ...
- BZOJ1797:[AHOI2009]最小割(最小割)
Description A,B两个国家正在交战,其中A国的物资运输网中有N个中转站,M条单向道路.设其中第i (1≤i≤M)条道路连接了vi,ui两个中转站,那么中转站vi可以通过该道路到达ui中转站 ...
- [AHOI2009]最小割 最小割可行边&必须边
~~~题面~~~ 题解: 做这题的时候才知道有最小割可行边和必须边这种东西..... 1,最小割可行边, 意思就是最小割中可能出现的边. 充要条件: 1,满流 2,在残余网络中找不到x ---> ...
- [BZOJ1797][AHOI2009]最小割Mincut
bzoj luogu sol 一条边出现在最小割集中的必要条件和充分条件. 先跑出任意一个最小割,然后在残余网络上跑出\(scc\). 一条边\((u,v)\)在最小割集中的必要条件:\(bel[u] ...
- 洛谷$P4126\ [AHOI2009]$最小割 图论
正解:网络流+$tarjan$ 解题报告: 传送门$QwQ$ $umm$最小割的判定问题$QwQ$,因为并不会做是看的题解才会的,所以也没什么推导过程直接放结论趴$QwQ$ 首先跑个最大流,然后有. ...
随机推荐
- tomcat错误信息解决方案【严重:StandardServer.await: create[8005]
1.独立运行的tomcat.exe没有关闭,关闭tomcat图标并结束掉tomcat进程.(我是这个原因,在开始菜单里找到tomcat,然后stop它) 2.安装了其他的软件占用了8080端口,tom ...
- 08_rlCoachKin自主编译,调试
为了知道参数的意思,以及为了从头建立一个项目,我从使用QTCreator来单独建立项目(当然也可以直接使用源代码中建立好的VS项目). 其实也推荐 VS2010调试 如果是用自带的VS项目,那么我们需 ...
- 鸟哥笔记:linux系统日志文件介绍
简单的说日志文件就是记录系统活动信息的几个文件,例如:何时.何地(来源ip).何人(什么服务名称).做了什么操作.换句话说就是:记录系统在什么时候由哪个进程做了什么样的行为时,发生了什么事件等. 日志 ...
- JavaScript 继承的几种模式
/** * Created by 2016 on 2016/6/5. */ //1.原型链继承 //把子类的原型,定义为超类的实例 通过原型来访问超类的方法和属性 function Person(){ ...
- 51nod1057 N的阶乘
输入N求N的阶乘的准确值. Input 输入N(1 <= N <= 10000) Output 输出N的阶乘 Input示例 5 Output示例 120参考博客:blog.csdn. ...
- PHP学习心得(二)——实用脚本
<?php 来表示 PHP 标识符的起始,然后放入 PHP 语句并通过加上一个终止标识符 ?> 来退出 PHP 模式 调用函数phpinfo(),将会看到很多自己系统的信息,以及预定义变量 ...
- Windows 下Python操作MySQL
1.环境要求(Win7 X64): python 2.7, MySQL-python-1.2.3.win-amd64-py2.7 :http://www.codegood.com/download/1 ...
- vb delphi7、2010 csharp vb.net空白测试程序
工作中难免在网上看到一段不错的代码,希望能够拿来测试一次,为了避免每次测试都要新建一个空白测试程序,索性预先建立好,要用的时候复制一遍,然后打开直接粘贴需要测试的代码进行测试.
- java项目使用的DBhelper类
import java.io.*; import java.sql.*; import java.util.*; import javax.servlet.jsp.jstl.sql.*; public ...
- easyui 汉化问题
遇到 easyui 需要汉化的 , 1: 找到 汉化文件 ,文件位于 插件的 locale 文件夹 内 easyui-lang-zh_CN.js 2: 将其 加载 与 easyui 之后 <s ...