bzoj1797
其实我觉得这种题目风格很像今天省选第三轮D1T1
都是在一个算法模型上去探索规律;
首先我们要做一遍最大流毫无疑问
第一问看起来很好想,只要是满流边就可以了?
错,反例不难找到
如:1--->2 flow 4
2--->3 flow 4
3--->1 flow 4
1--->4 flow 4
很有可能我们在找增广路的时候,走了多余的回路(1-2-3-1),导致前3条边也是满流边,但不会出现在最小割方案中
所以我们考虑用tarjan对残留网络缩点;
对于第一问,要求是满流边且起点终点在不同集合
第二问,显然在满足第一问的前提下,起点终点分属源点汇点集合
const inf=;
type node=record
from,point,next,flow:longint;
end; var edge:array[..] of node;
ans1,ans2:array[..] of longint;
p,cur,pre,numh,h,low,dfn,be,st:array[..] of longint;
tot,d,r,x,y,z,i,j,n,m,s,t,len:longint;
v,f:array[..] of boolean; function min(a,b:longint):longint;
begin
if a>b then exit(b) else exit(a);
end; procedure add(x,y,f:longint);
begin
inc(len);
edge[len].point:=y;
edge[len].from:=x;
edge[len].flow:=f;
edge[len].next:=p[x];
p[x]:=len;
end; procedure sap;
var u,i,j,tmp,neck,q:longint;
begin
u:=s;
numh[]:=n;
while h[s]<n do
begin
if u=t then
begin
i:=s;
neck:=inf;
while i<>t do
begin
j:=cur[i];
if neck>edge[j].flow then
begin
neck:=edge[j].flow;
q:=i;
end;
i:=edge[j].point;
end;
i:=s;
while i<>t do
begin
j:=cur[i];
dec(edge[j].flow,neck);
inc(edge[j xor ].flow,neck);
i:=edge[j].point;
end;
u:=q;
end;
q:=-;
i:=p[u];
while i<>- do
begin
j:=edge[i].point;
if (edge[i].flow>) and (h[u]=h[j]+) then
begin
q:=i;
break;
end;
i:=edge[i].next;
end;
if q<>- then
begin
cur[u]:=q;
pre[j]:=u;
u:=j;
end
else begin
dec(numh[h[u]]);
if numh[h[u]]= then exit;
tmp:=n;
i:=p[u];
while i<>- do
begin
j:=edge[i].point;
if edge[i].flow> then tmp:=min(tmp,h[j]);
i:=edge[i].next;
end;
h[u]:=tmp+;
inc(numh[h[u]]);
if u<>s then u:=pre[u];
end;
end;
end; procedure tarjan(x:longint);
var i,y:longint;
begin
v[x]:=true;
f[x]:=true;
inc(r);
inc(d);
st[r]:=x;
dfn[x]:=d;
low[x]:=d;
i:=p[x];
while i<>- do
begin
y:=edge[i].point;
if edge[i].flow> then
begin
if not v[y] then
begin
tarjan(y);
low[x]:=min(low[x],low[y]);
end
else if f[y] then
low[x]:=min(low[x],low[y]);
end;
i:=edge[i].next;
end;
if low[x]=dfn[x] then
begin
inc(tot);
while st[r+]<>x do
begin
y:=st[r];
f[y]:=false;
be[y]:=tot;
dec(r);
end;
end;
end; begin
readln(n,m,s,t);
len:=-;
fillchar(p,sizeof(p),);
for i:= to m do
begin
readln(x,y,z);
add(x,y,z);
add(y,x,);
end;
sap;
for i:= to n do
if not v[i] then
begin
r:=;
d:=;
tarjan(i);
end;
i:=;
while i<=len do
begin
if (edge[i].flow=) then
begin
x:=edge[i].from;
y:=edge[i].point;
if be[x]<>be[y] then
begin
ans1[i div +]:=;
if (be[x]=be[s]) and (be[y]=be[t]) or (be[x]=be[t]) and (be[y]=be[s]) then
ans2[i div +]:=;
end;
end;
i:=i+;
end;
for i:= to m do
writeln(ans1[i],' ',ans2[i]);
end.
bzoj1797的更多相关文章
- 【bzoj1797】 Ahoi2009—Mincut 最小割
http://www.lydsy.com/JudgeOnline/problem.php?id=1797 (题目链接) 题意 求一条边是否可能在一个最小割集中,以及这条边是否一定在最小割集中. Sol ...
- 【BZOJ1797】[AHOI2009]最小割(网络流)
[BZOJ1797][AHOI2009]最小割(网络流) 题面 BZOJ 洛谷 题解 最小割的判定问题,这里就当做记结论吧.(源自\(lun\)的课件) 我们先跑一遍最小割,求出残量网络.然后把所有还 ...
- 【BZOJ-1797】Mincut 最小割 最大流 + Tarjan + 缩点
1797: [Ahoi2009]Mincut 最小割 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1685 Solved: 724[Submit] ...
- bzoj1797: [Ahoi2009]Mincut 最小割
最大流+tarjan.然后因为原来那样写如果图不连通的话就会出错,WA了很久. jcvb: 在残余网络上跑tarjan求出所有SCC,记id[u]为点u所在SCC的编号.显然有id[s]!=id[t] ...
- BZOJ1797:[AHOI2009]最小割(最小割)
Description A,B两个国家正在交战,其中A国的物资运输网中有N个中转站,M条单向道路.设其中第i (1≤i≤M)条道路连接了vi,ui两个中转站,那么中转站vi可以通过该道路到达ui中转站 ...
- 【bzoj1797】[Ahoi2009]Mincut 最小割 网络流最小割+Tarjan
题目描述 给定一张图,对于每一条边询问:(1)是否存在割断该边的s-t最小割 (2)是否所有s-t最小割都割断该边 输入 第一行有4个正整数,依次为N,M,s和t.第2行到第(M+1)行每行3个正 整 ...
- 【最小割】【Dinic】【强联通分量缩点】bzoj1797 [Ahoi2009]Mincut 最小割
结论: 满足条件一:当一条边的起点和终点不在 残量网络的 一个强联通分量中.且满流. 满足条件二:当一条边的起点和终点分别在 S 和 T 的强联通分量中.且满流.. 网上题解很多的. #include ...
- [BZOJ1797][AHOI2009]最小割Mincut
bzoj luogu sol 一条边出现在最小割集中的必要条件和充分条件. 先跑出任意一个最小割,然后在残余网络上跑出\(scc\). 一条边\((u,v)\)在最小割集中的必要条件:\(bel[u] ...
- BZOJ1797 [Ahoi2009]Mincut 最小割 【最小割唯一性判定】
题目 A,B两个国家正在交战,其中A国的物资运输网中有N个中转站,M条单向道路.设其中第i (1≤i≤M)条道路连接了vi,ui两个中转站,那么中转站vi可以通过该道路到达ui中转站,如果切断这条道路 ...
随机推荐
- gradle使用国内源
// 设置 maven 库地址 repositories { maven { url 'http://maven.oschina.net/content/groups/public/' } } ...
- Passbook教程中生成pass时遇到的“Couldn't find a passTypeIdentifier in the pass”
报错如下: 2014-03-28 15:19:17.990 signpass[6358:507] Couldn't find a passTypeIdentifier in the pass 解决方案 ...
- HTML5入门篇
---- HTML5简介 HTML5 是用于取代1999年所制定的 HTML 4.01 和 XHTML 1.0 标准的 HTML 标准版本,现在仍处于发展阶段,但大部分浏览器已经支持某些 HTML5 ...
- CentOS 7 install LNMP
CentOS 7 install LNMP 关于 Nginx (发音 “engine x”)这是一款免费.开源.高效的 HTTP 服务器,Nginx是以稳定著称,丰富的功能,结构简单,低资源消耗.本教 ...
- svg学习笔记(一)
SVG——可扩展适量图形,基于XML PC端:IE9+ wap端:表现良好,适合使用 基础图形: line(线段) <line x1="25" y1="150 ...
- STM32F407移植contiki2.6后使用LWIP库实现tcp client
最近在做智能家居,物联网项目,用到了C下的contiki移植 经过一阵调试,终于在 STM32F407移植contiki2.6后使用LWIP库实现tcp client. 一路艰辛谁人知道....唯有留 ...
- 如何让sudo命令不需要输入密码就可执行
通过visudo 来编辑/etc/sudoers来实现 在该文件中追加一下记录即可 username ALL=(ALL) NOPASSWD:ALL ——-下面文章转载自网络———– # User pr ...
- Python 基础篇:字符串、列表操作
字符串操作 判断是否为数字 string = "200" string.isdigit() >>false 待完善.. 列表操作 列表是我们最以后最常用的数据类型之一, ...
- Oracle datafile特殊字符处理
1.发现数据库的数据文件有特殊字符: 2.尝试在sqlplus下用将tablespace offline后修改 SQL> alter tablespace WST_DATA rename dat ...
- 微信支付JS API使用心得
微信的接口真的很坑爹,只返回成功或失败,从来不会告诉你为什么失败.这个微信支付的js接口也是调了一个下午才成功,期间踩了不少坑,在这里总结一下,而且把支付接口封装成了一个js文件,这样以后调用就很方便 ...