bzoj 1797: [Ahoi2009]Mincut 最小割 (网络流)
太神了直接看了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 最小割 (网络流)的更多相关文章
- BZOJ 1797: [Ahoi2009]Mincut 最小割( 网络流 )
先跑网络流, 然后在残余网络tarjan缩点. 考虑一条边(u,v): 当且仅当scc[u] != scc[v], (u,v)可能出现在最小割中...然而我并不会证明 当且仅当scc[u] = scc ...
- BZOJ 1797: [Ahoi2009]Mincut 最小割
1797: [Ahoi2009]Mincut 最小割 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2076 Solved: 885[Submit] ...
- ●BZOJ 1797 [Ahoi2009]Mincut 最小割
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=1797 题解: 详细的讲解去看http://hzwer.com/3217.html首先跑一个最 ...
- bzoj 1797: [Ahoi2009]Mincut 最小割【tarjan+最小割】
先跑一遍最大流,然后对残量网络(即所有没有满流的边)进行tarjan缩点. 能成为最小割的边一定满流:因为最小割不可能割一半的边: 连接s.t所在联通块的满流边一定在最小割里:如果不割掉这条边的话,就 ...
- 1797: [Ahoi2009]Mincut 最小割
1797: [Ahoi2009]Mincut 最小割 链接 分析: 题意为:问一条边是否可能存在于最小割中,是否一定存在于最小割中. 首先最小割的边一定是满流的边.且这条边点两个端点u.v中,至少一个 ...
- 【bzoj1797】[Ahoi2009]Mincut 最小割 网络流最小割+Tarjan
题目描述 给定一张图,对于每一条边询问:(1)是否存在割断该边的s-t最小割 (2)是否所有s-t最小割都割断该边 输入 第一行有4个正整数,依次为N,M,s和t.第2行到第(M+1)行每行3个正 整 ...
- bzoj1797: [Ahoi2009]Mincut 最小割
最大流+tarjan.然后因为原来那样写如果图不连通的话就会出错,WA了很久. jcvb: 在残余网络上跑tarjan求出所有SCC,记id[u]为点u所在SCC的编号.显然有id[s]!=id[t] ...
- bzoj1797: [Ahoi2009]Mincut 最小割(最小割+强联通tarjan)
1797: [Ahoi2009]Mincut 最小割 题目:传送门 题解: 感觉是一道肥肠好的题目. 第二问其实比第一问简单? 用残余网络跑强联通,流量大于0才访问. 那么如果两个点所属的联通分量分别 ...
- BZOJ_1797_[Ahoi2009]Mincut 最小割_最小割+tarjan
BZOJ_1797_[Ahoi2009]Mincut 最小割_最小割+tarjan Description A,B两个国家正在交战,其中A国的物资运输网中有N个中转站,M条单向道路.设其中第i (1≤ ...
随机推荐
- redhat防火墙管理
systemctl status firewalldsystemctl stop firewalldsystemctl start firewalldsystemctl enable firewall ...
- 「日常训练」Kefa and Dishes(Codeforces Round #321 Div. 2 D)
题意与分析(CodeForces 580D) 一个人有\(n\)道菜,然后要点\(m\)道菜,每道菜有一个美味程度:然后给你了很多个关系,表示如果\(x\)刚好在\(y\)前面做的话,他的美味程度就会 ...
- Codeforces Round #495 (Div. 2) Sonya and Matrix
正常没有正方形的限制下,值为i的点个数4i 那么从0开始遍历,第一个不为4i的值就是min(x, y) 由于对称性我们姑且令x为这个值 我们先列举n*m=t的各种情况 对于一对n, m.我们已经知道n ...
- 域名、IP地址、URL关系
域名是个文字形式记录的IP地址 IP地址是计算机在网络中的门牌号! URL是网页地址 例如1: http://zhidao.baidu.com/question/14674128.html 是URL ...
- [JSON].set(keyPath, value)
语法:[JSON].set( keyPath, value ) 返回:[True | False] 说明:设置键值 参数: keyPath [keyPath 必需] 键名路径字符串 value ...
- lintcode50 数组剔除元素后的乘积
数组剔除元素后的乘积 给定一个整数数组A. 定义B[i] = A[0] * ... * A[i-1] * A[i+1] * ... * A[n-1], 计算B的时候请不要使用除法. 您在真实的面试中是 ...
- (转)CGMA - Organic World Building in UE4: week 6
原文:丢失,这篇是艺术家博客上发现的,小道整理笔记中,临时放于效果案例目录. In this week we focused on creating the grass and flora t ...
- 从零开始的Python学习Episode 2——运算符与while循环
一.算术运算符 加法:+,减法:-,乘法*,除法/,整除(地板除)//,取余%,乘方**. 二.逻辑运算符 且:and,或:or,非:not 优先级:not>and>or 短路原则: 对 ...
- 关于mysql开元数据库的几个随想
现在已经是凌晨了,昨天晚上写了我人生中的第一篇笔记,觉得没什么可写的,写了一个多小时都没写出什么,现在突然想写点东西了,这是一个比较有趣的问题,前两个月换了新工作,记得当初面试这份工作的时候面试到第三 ...
- opencv-学习笔记(1)常用函数和方法。
opencv-学习笔记(1)常用函数和方法. cv2.imread(filename,falg) filename是文件名字 flag是读入的方式 cv2.MREAD_UNCHANGED :不进行转化 ...