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$ 首先跑个最大流,然后有. ...
随机推荐
- CentOS配置java运行环境
CentOS_配置_docker CentOS_6.5 1.CentOS_6.5在安装docker-io之前需要首先卸载docker包(没下载过可以省略) $ sudo yum -y remove d ...
- java多线程之停止线程
/*1.让各个对象或类相互灵活交流2.两个线程都冻结了,就不能唤醒了,因为根据代码要一个线程活着才能执行唤醒操作,就像玩木游戏3.中断状态就是冻结状态4.当主线程退出的时候,里面的两个线程都处于冻结状 ...
- 4.MySQL连接并选择数据库(SQL & C)
在连接了MySQL数据库之后,可以通过SQL命令或者C.PHP.JAVA等程序来指定需要操作的数据库.这里主要介绍SQL命令和相应的C程序. 首先创建用户rick(赋予所有权限) mysql> ...
- Web前端新人笔记之CSS字体
本章内容是阅读CSS权威指南的一个小积累和随笔.新人必看,老鸟也可查看并指出不足指出以便后人阅读更好地理解.O(∩_∩)O谢谢!!!设置字体属性时样式变的最常见的用途之一:不过,尽管字体选择很重要,但 ...
- xml simpleXML_load_file(), simpleXML_load_string()
xml.xml文件 <?xml version='1.0'?><man> <att> <name>lin3615</name& ...
- 【转】C# Excel 导入到 Access数据库表(winForm版)
/// <summary> /// 获取Excel文件 /// </summary> /// <param name="sender">< ...
- java异常处理机制 (转载)
java异常处理机制 本文来自:曹胜欢博客专栏.转载请注明出处:http://blog.csdn.net/csh624366188 异常处理是程序设计中一个非常重要的方面,也是程序设计的一大难点,从C ...
- Oracle表添加主键、外键
1.创建表的同时创建主键约束 (1)无命名 create table student ( studentid int primary key not null, studentname varchar ...
- HDFS文件读写流程 (转)
文件读取的过程如下: 使用HDFS提供的客户端开发库Client,向远程的Namenode发起RPC请求: Namenode会视情况返回文件的部分或者全部block列表,对于每个block,Namen ...
- ViewController 之间设置转场动画
AddOrEditViewController *addOrEdit = [[AddOrEditViewController alloc] init]; CATransition *transitio ...