太神了直接看了hzwer的题解,有个新认识,一条路径上满流的一定是这条路径上所有边的最小值。

type
arr=record
toward,next,cap,from:longint;
end;
const
maxm=;
maxn=;
var
edge:array[..maxm]of arr;
first,cur,d,p,gap:array[..maxn]of longint;
chose1,chose2:array[..maxn]of boolean;
n,m,s,t,tot,esum:longint; function min(x,y:longint):longint;
begin
if x<y then exit(x);
exit(y);
end; procedure add(j,k,l:longint);
begin
inc(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);
begin
add(j,k,l);
add(k,j,);
end; function sap(x,flow:longint):longint;
var
now,more,i,too:longint;
begin
if x=t then exit(flow);
now:=;
i:=cur[x];
while i>= do begin
too:=edge[i].toward;
if (d[x]=d[too]+) and (edge[i].cap>) then begin
more:=sap(too,min(flow-now,edge[i].cap));
dec(edge[i].cap,more);
inc(edge[i xor ].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]]= then d[s]:=n;
inc(d[x]);
inc(gap[d[x]]);
cur[x]:=first[x];
exit(now);
end; procedure maxflow;
var
i:longint;
begin
fillchar(d,sizeof(d),);
fillchar(gap,sizeof(gap),);
gap[]:=n;
for i:= to n do cur[i]:=first[i];
while d[s]<n do sap(s,maxlongint);
end; procedure into;
var
i,j,k,l:longint;
begin
esum:=-;
fillchar(first,sizeof(first),);
readln(n,m,s,t);
for i:= to m do begin
readln(j,k,l);
addedge(j,k,l);
end;
end; procedure work;
var
head,tail,x,y,i,j,too:longint;
begin
maxflow;
{ for i:=0 to m<<1 do
writeln(edge[i].from,' ',edge[i].toward,' ',edge[i].next,' ',edge[i].cap); }
head:=;
tail:=;
p[]:=s;
fillchar(chose1,sizeof(chose1),false);
chose1[s]:=true;
while head<=tail do begin
x:=p[head];
i:=first[x];
while i>= do begin
too:=edge[i].toward;
if (edge[i].cap>) and (not chose1[too]) then begin
inc(tail);
p[tail]:=too;
chose1[too]:=true;
end;
i:=edge[i].next;
end;
inc(head);
end;
//for i:= to n do writeln(i,' ',chose1[i]);
head:=;
tail:=;
p[]:=t;
fillchar(chose2,sizeof(chose2),false);
chose2[t]:=true;
while head<=tail do begin
x:=p[head];
i:=first[x];
while i>= do begin
too:=edge[i].toward;
if (edge[i xor ].cap>) and (not chose2[too]) then begin
inc(tail);
p[tail]:=too;
chose2[too]:=true;
end;
i:=edge[i].next;
end;
inc(head);
end;
//for i:= to n do writeln(i,' ',chose2[i]);
for i:= to m do begin
j:=(i-)<<;
if edge[j].cap> then begin
writeln(,' ',);
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() else write();
write(' ');
if (chose1[x] and chose2[y]) or (chose1[y] and chose2[x])then writeln() else writeln();
end;
readln;
end; begin
into;
work;
end.

bzoj 1797: [Ahoi2009]Mincut 最小割 (网络流)的更多相关文章

  1. BZOJ 1797: [Ahoi2009]Mincut 最小割( 网络流 )

    先跑网络流, 然后在残余网络tarjan缩点. 考虑一条边(u,v): 当且仅当scc[u] != scc[v], (u,v)可能出现在最小割中...然而我并不会证明 当且仅当scc[u] = scc ...

  2. BZOJ 1797: [Ahoi2009]Mincut 最小割

    1797: [Ahoi2009]Mincut 最小割 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2076  Solved: 885[Submit] ...

  3. ●BZOJ 1797 [Ahoi2009]Mincut 最小割

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=1797 题解: 详细的讲解去看http://hzwer.com/3217.html首先跑一个最 ...

  4. bzoj 1797: [Ahoi2009]Mincut 最小割【tarjan+最小割】

    先跑一遍最大流,然后对残量网络(即所有没有满流的边)进行tarjan缩点. 能成为最小割的边一定满流:因为最小割不可能割一半的边: 连接s.t所在联通块的满流边一定在最小割里:如果不割掉这条边的话,就 ...

  5. 1797: [Ahoi2009]Mincut 最小割

    1797: [Ahoi2009]Mincut 最小割 链接 分析: 题意为:问一条边是否可能存在于最小割中,是否一定存在于最小割中. 首先最小割的边一定是满流的边.且这条边点两个端点u.v中,至少一个 ...

  6. 【bzoj1797】[Ahoi2009]Mincut 最小割 网络流最小割+Tarjan

    题目描述 给定一张图,对于每一条边询问:(1)是否存在割断该边的s-t最小割 (2)是否所有s-t最小割都割断该边 输入 第一行有4个正整数,依次为N,M,s和t.第2行到第(M+1)行每行3个正 整 ...

  7. bzoj1797: [Ahoi2009]Mincut 最小割

    最大流+tarjan.然后因为原来那样写如果图不连通的话就会出错,WA了很久. jcvb: 在残余网络上跑tarjan求出所有SCC,记id[u]为点u所在SCC的编号.显然有id[s]!=id[t] ...

  8. bzoj1797: [Ahoi2009]Mincut 最小割(最小割+强联通tarjan)

    1797: [Ahoi2009]Mincut 最小割 题目:传送门 题解: 感觉是一道肥肠好的题目. 第二问其实比第一问简单? 用残余网络跑强联通,流量大于0才访问. 那么如果两个点所属的联通分量分别 ...

  9. BZOJ_1797_[Ahoi2009]Mincut 最小割_最小割+tarjan

    BZOJ_1797_[Ahoi2009]Mincut 最小割_最小割+tarjan Description A,B两个国家正在交战,其中A国的物资运输网中有N个中转站,M条单向道路.设其中第i (1≤ ...

随机推荐

  1. 阅读笔记《JavaScript高级程序设计》

    0. 严格模式 "user strict" (1整个脚本顶部,2函数体顶部) 1. 数据类型 undefined -- 未定义 boolean string number obje ...

  2. leetcode--笔记8 Fizz Buzz

    题目要求: Write a program that outputs the string representation of numbers from 1 to n. But for multipl ...

  3. docker社区的geodata/gdal镜像dockerfile分析

    对应从事遥感与地理信息的同仁来说,gdal应该是所有工具中使用频度最高的库了,那么在docker中使用gdal时,面临的第一步就是构建gdal基础镜像,社区中引用最多的就是geodata提供的gdal ...

  4. join_tab计算代价

    此路不通,还是需要按照顺序进行计算

  5. JAVA基础学习之路(四)定义简单java类

    简单java类开发一般原则: 类名称必须有意义,再怎么说,要让人家看的明白吧 类之中所有属性必须使用private封装,并提供setter,getter方法 类之中可以有多个构造方法,但是必须保留有一 ...

  6. spark提交任务的两种的方法

    在学习Spark过程中,资料中介绍的提交Spark Job的方式主要有两种(我所知道的): 第一种: 通过命令行的方式提交Job,使用spark 自带的spark-submit工具提交,官网和大多数参 ...

  7. ubuntu networking 与 network-manager

    刚遇到的坑,因为操作不当导致网络中断,于是手动配置了/etc/network/interfaces , 修复了系统之后发现ubuntu-desktop中的有线链接不见了,百度了一下说是networki ...

  8. python常用命令—终端安装win32的两种方法

    1, pip install pywin32 2, pip install pypiwin32

  9. truffle运行特殊 无法找到module的处理方法

    https://blog.csdn.net/SnWJy/article/details/80549227 错误描述: ​ truffle项目根目录执行truffle compile时,报错'modul ...

  10. for和foreach的一点总结

    两者都是数组的循环遍历,但是区别还是有点: for循环,如果块内有事件操作,那么i是不会等事件操作时候在依次增加,而是一次性走完,,也就是依靠下标定位,下标已经走完了,而foreah是依次增加,它是依 ...