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≤ ...
随机推荐
- 使用Google Cloud Messaging (GCM),PHP 开发Android Push Notifications (安卓推送通知)
什么是GCM? Google Cloud Messaging (GCM) 是Google提供的一个服务,用来从服务端向安卓设备发送推送通知. GCM分为客户端和服务端开发. 这里我们只介绍服务端开发 ...
- 抽样分布(2) t分布
定义 t分布 设X ~ N(0,1),Y ~ χ2(n),且X,Y相互独立,则称随机变量 服从自由度为n的t分布(学生氏分布) 记为 t~t(n),其概率密度为 由于tn(x)是偶函数,其图形关于y轴 ...
- leetcode笔记--7 Find the Difference
question: Given two strings s and t which consist of only lowercase letters. String t is generated b ...
- CSS选择器语法&示例
CSS3 选择器 在 CSS 中,选择器是一种模式,用于选择需要添加样式的元素. "CSS" 列指示该属性是在哪个 CSS 版本中定义的.(CSS1.CSS2 还是 CSS3.) ...
- caffe Mac 安装
参考了 https://zhuanlan.zhihu.com/p/24853767 安装caffe的依赖项 brew install --fresh -vd snappy leveldb gflags ...
- python学习笔记02 --------------基础数据类型
python的基本数据类型: 1.基本数据 1.1. 数字类型 1.1.1 整数 int int() #将括号内内容转化为整数类型. 1.1.2 浮点数 float 1.1.3 复 ...
- LeetCode 98——验证二叉搜索树
1. 题目 2. 解答 2.1. 方法一 我们初始化根节点的范围为长整形数据的最小最大值 \([LONG\_MIN,LONG\_MAX]\),则其左子节点的取值范围为 \([LONG\_MIN,根节点 ...
- [转载]Tensorflow中reduction_indices 的用法
Tensorflow中reduction_indices 的用法 默认时None 压缩成一维
- maven 教程二 深入
一:编写POM <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w ...
- [leetcode-775-Global and Local Inversions]
We have some permutation A of [0, 1, ..., N - 1], where N is the length of A. The number of (global) ...