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中转站,如果切断这条道路 ...
随机推荐
- 使用SQL Server 2005 新的语法ROW_NUMBER()进行分页的两种不同方式的性能比较
相比在SQL Server 2000 中使用的分页方式,在SQL Server 2005中使用新的语法ROW_NUMBER()来分页效率要高出很多,但是很多人在使用ROW_NUMBER()这种分页方式 ...
- Java实战之02Hibernate-04多表映射
十.多表映射 0.内容补充:数据完整性 作用:防止用户的误操作. 实体完整性:主键.用于确定表中唯一的一条记录. 域完整性:表中的字段. 数据类型约束: 非空约束: 唯一约束: 参照完整性: 多表设计 ...
- FreeMarker-Built-ins for numbers
http://freemarker.org/docs/ref_builtins_number.html#topic.extendedJavaDecimalFormat Page Contents ab ...
- InstallShield : 如何查找编译后的 Merge Module存放路径
工程菜单栏中依次选择 Tools ---> Options… ,选择 Merge Modules tab 页,如下,就会看到Merge Module的存放路径,也可以根据需求修改. Merge ...
- dialog的传值
A页面 等待B页面返回值的textBox:<asp:TextBox ID="TextBox1" runat="server"></asp:Te ...
- Linux下Qt环境的搭建
之前一直使用Ubuntu软件中心中的Qt4开发Qt的应用程序,现在转到Linux下来做Qt5开发,但是必须从Qt官网上面下载对应的安装包,配置起来相对麻烦一些,这里介绍整个开发流程. 首先,在官网上面 ...
- jQuery Mobile里xxx怎么用呀? (事件篇)
jQuery Mobile里$(document).ready()怎么用呀? 相关链接: http://stackoverflow.com/questions/14468659/jquery-mobi ...
- html5 meta头部设置
<meta name="viewport" content="height=[pixel_value | device-height], width=[pixel_ ...
- iframe 适用高度
contentWindow 兼容各个浏览器,可取得子窗口的 window 对象. contentDocument Firefox 支持,> ie8 的ie支持.可取得子窗口的 document ...
- Random.Next获取随即数
Random random = new Random(); random.Next()--------------返回非负的一个随机数. random.Next(int maxValue)----- ...