~~~题面~~~

题解:

做这题的时候才知道有最小割可行边和必须边这种东西。。。。。

1,最小割可行边,

意思就是最小割中可能出现的边。

充要条件:

  1,满流

  2,在残余网络中找不到x ---> y的路径

解释:

如果在残余网络中还找得到x ---> y的路径的话,要割掉这条边就还需要割掉另一条路径,这显然是不够优的。

如果是满流的话显然不是割掉了这条边

2,最小割必须边

  1,满流

  2,在残余网络中s 可以到 x, y 可以到 t。

解释:

满流的原因和上面原因,同时必须边肯定也是可行边(显然可行边的范围就要大一些嘛)。

如果满流但s不能到x or y 不能到 t,因为这样的话说明在s 到 x(y 到 t)的路上就已经被割掉了,而不是在这里割的。

但是因为满流了,所以这是可行的,但是由于割在别的地方,说明不是必须的。

因此s 必须可以到 x, y 必须可以到s才能保证是必须边,而不是可行边

至于实现方法就比较妙了。

如果两个点在一个scc中则表示可以到。

因此可行边需要保证x和y不在一个scc中。

而必须边则还需要额外保证s 和 x 属于一个scc, y 和 t属于一个scc

 #include<bits/stdc++.h>
using namespace std;
#define R register int
#define getchar() *o++
#define inf 2139062143
#define AC 5000
#define ac 150000
#define D printf("line in %d\n", __LINE__);
char READ[], *o = READ;
int n, m, s, t, ans, x, cnt, addflow;
int last[AC], c[AC], have[AC], good[AC];
int date[ac], Next[ac], belong[ac], haveflow[ac], Head[AC], tot = ;//前向星
int low[AC], dfn[AC], scc[AC], timer;//tarjan
int q[AC], head, tail;//队列
int Stack[AC], top;
bool z[AC];//用于tarjan inline int read()
{
int x = ; char c = getchar();
while(c > '' || c < '') c = getchar();
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x;
} inline void upmin(int &a, int b)
{
if(a > b) a = b;
} inline void add(int f, int w, int S)
{
date[++tot] = w, Next[tot] = Head[f], Head[f] = tot, haveflow[tot] = S, belong[tot] = f;
date[++tot] = f, Next[tot] = Head[w], Head[w] = tot;
} void pre()
{
int u, v, e;
n = read(), m = read(), s = read(), t = read();
for(R i = ; i <= m; i++)
{
u = read(), v = read(), e = read();
add(u, v, e);
}
} void bfs()
{
int x, now;
c[t] = , have[] = , q[++tail] = t;
while(head < tail)
{
x = q[++head];
for(R i = Head[x]; i ; i = Next[i])
{
now = date[i];
if(haveflow[i ^ ] && !c[now])
{
c[now] = c[x] + ;
++have[c[now]];
q[++tail] = now;
}
}
}
memcpy(good, Head, sizeof(good));
} void aru()
{
while(x != s)
{
haveflow[last[x]] -= addflow;
haveflow[last[x] ^ ] += addflow;
x = date[last[x] ^ ];
}
ans += addflow;
} void isap()
{
int now; bool done;
x = s, addflow = inf;
while(c[s] != )
{
if(x == t) aru(), addflow = inf;
done = false;
for(R i = good[x]; i ; i = Next[i])
{
now = date[i];
if(haveflow[i] && c[now] == c[x] - )
{
done = true;
upmin(addflow, haveflow[i]);
good[x] = last[now] = i;
x = now;
break;
}
}
if(!done)
{
int go = ;
for(R i = Head[x]; i ; i = Next[i])
{
now = date[i];
if(haveflow[i] && c[now]) upmin(go, c[now]);
}
good[x] = Head[x];//error!!!不要忘了重置
if(!(--have[c[x]])) break;
++have[c[x] = go + ];
if(x != s) x = date[last[x] ^ ];
}
}
} void tarjan(int x)
{
int now;
dfn[x] = low[x] = ++timer;
z[x] = true;
Stack[++top] = x;
for(R i = Head[x]; i ; i = Next[i])
{
if(!haveflow[i]) continue;//流满表示不联通
now = date[i];
if(!dfn[now])
{
tarjan(now);
upmin(low[x], low[now]);
}
else if(z[now]) upmin(low[x], low[now]);
}
if(dfn[x] == low[x])
{
++cnt;
while(Stack[top] != x)
{
now = Stack[top--];
scc[now] = cnt;
z[now] = false;
}
now = Stack[top--];
scc[now] = cnt;
z[now] = false;
}
} void work()
{
int x, y;
for(R i = ; i <= tot; i += )
{
x = belong[i], y = date[i];
// printf("%d %d\n", x, y);
if(!haveflow[i] && scc[x] != scc[y])
{
printf("1 ");
if(scc[x] == scc[s] && scc[y] == scc[t]) printf("1\n");
else printf("0\n");
}
else printf("0 0\n");
}
} int main()
{
// freopen("in.in", "r", stdin);
fread(READ, , , stdin);
pre();
bfs();
isap();
for(R i=;i<=n;i++)
if(!dfn[i]) tarjan(i);
// for(R i=1;i<=n;i++) printf("%d ", scc[i]);
// printf("\n");
// for(R i=2;i<=tot;i++) printf("%d ", haveflow[i]);
work();
// fclose(stdin);
return ;
}

[AHOI2009]最小割 最小割可行边&必须边的更多相关文章

  1. BZOJ 1797 网络流的可行边&必须边

    求完网络流以后 tarjan一发 判一判 //By SiriusRen #include <queue> #include <bitset> #include <cstd ...

  2. 最小割求法&&可行边和必须边

    最小割的可行边与必须边 就是在残量网络上跑tarjan 可行边: 满流并且残量网络上不能存在入点到出点的路径 必须边: 满流并且残量网络上入点能从源点到达,出点能到汇点. 任意一种最小割求法: 跑一边 ...

  3. scu - 3254 - Rain and Fgj(最小点权割)

    题意:N个点.M条边(2 <= N <= 1000 , 0 <= M <= 10^5),每一个点有个权值W(0 <= W <= 10^5),现要去除一些点(不能去掉 ...

  4. 算法笔记--最大流和最小割 && 最小费用最大流 && 上下界网络流

    最大流: 给定指定的一个有向图,其中有两个特殊的点源S(Sources)和汇T(Sinks),每条边有指定的容量(Capacity),求满足条件的从S到T的最大流(MaxFlow). 最小割: 割是网 ...

  5. 3532: [Sdoi2014]Lis 最小字典序最小割

    3532: [Sdoi2014]Lis Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 865  Solved: 311[Submit][Status] ...

  6. 紫书 例题 11-2 UVa 1395(最大边减最小边最小的生成树)

    思路:枚举所有可能的情况. 枚举最小边, 然后不断加边, 直到联通后, 这个时候有一个生成树.这个时候,在目前这个最小边的情况可以不往后枚举了, 可以直接更新答案后break. 因为题目求最大边减最小 ...

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

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

  8. BZOJ1797:[AHOI2009]最小割(最小割)

    Description A,B两个国家正在交战,其中A国的物资运输网中有N个中转站,M条单向道路.设其中第i (1≤i≤M)条道路连接了vi,ui两个中转站,那么中转站vi可以通过该道路到达ui中转站 ...

  9. POJ 3308 Paratroopers(最大流最小割の最小点权覆盖)

    Description It is year 2500 A.D. and there is a terrible war between the forces of the Earth and the ...

随机推荐

  1. PHP调用wsdl接口实例化SoapClient抛出异常

    异常:Message:SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://*****?wsdl' : failed to load externa ...

  2. Python学习-猜数字游戏

    菩萨蛮·黄鹤楼 茫茫九派流中国,沉沉一线穿南北.烟雨莽苍苍,龟蛇锁大江. 黄鹤知何去,剩有游人处.把酒酹滔滔,心潮逐浪高! --coding:UTF-8-- import random secret ...

  3. C 基本运算

    一 算术运算 C语言一共有34种运算符 包括了常见的加减乘除运算 1. 加法运算+ 除开能做加法运算 还能表示正号: +5, +90 2. 减法运算- 除开能做减法运算 还能表示符号: -10, -2 ...

  4. 使用pycharm软件配置数据库可视化

    必须品: pycharm软件,专业版最好自带就有,社区版就需要安装下插件. 专业版直接会在右边的编辑框浮动,直接点开就可以配置. 如图所示,点开就可以配置相应的数据库, 点开配置完毕就可以使用了. 还 ...

  5. 《Git学习指南》学习笔记(三)

    多次提交 提交一般分未两步:add和commit. add将修改存入到索引(index)或叫暂存区(staging area)中. status命令 status命令会出现三种可能的状态: chang ...

  6. 下拉网页div自动浮在顶部

    <!DOCTYPE html> <html> <head> <title></title> <style type="tex ...

  7. Python基础 之 set集合 与 字符串格式化

    数据类型的回顾与总结 可变与不可变1.可变:列表,字典2.不可变:字符串,数字,元组 访问顺序:1.直接访问:数字2.顺序访问:字符串,列表,元祖3.映射:字典 存放元素个数:容器类型:列表,元祖,字 ...

  8. Python+Opencv实现把图片转为视频

    1. 安装Opencv包 在Python命令行输入如下命令(如果你使用的Anaconda,直接进入Anaconda Prompt键入命令即可.如果你不知道Anaconda是什么,可以参考王树义老师的文 ...

  9. parity 注记词

    spousal tint untold around rosy daintily unrated sheep choice showpiece chirping gala

  10. JS判断是IOS还是Android以及如何解决h5打包后在ios下内容与状态栏重叠问题

    h5打包后在ios下内容与状态栏重叠问题: 1:知道设备的类型: var u = navigator.userAgent, app = navigator.appVersion; var isAndr ...