~~~题面~~~

题解:

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

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. CSS3 子节点选择器

    CSS3中新增了几个子元素选择器,大大提高了开发者的开发效率.之前有些要通过为一个个子元素添加class,或者js实现才能实现的效果.现在可以很方便的用选择器实现. 这些新的样式已被现代浏览器及IE9 ...

  2. Restify Api 开发经验

    此文已由作者王振华授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 工作期间,一直在用Restify开发或维护大大小小的API系统,现在分享一下一些个人觉得不错的Tips. 充 ...

  3. Win10 远程服务器版

    朋友的电脑刚装了1803版的Win10,然后他用KMS_VL_ALL6.9激活了一下,竟然变成了一个奇怪的版本:“远程服务器版”!第一次见这玩意,还真稀罕.帮他研究了一下,发现KMS_VL_ALL在激 ...

  4. create-react-app react-redux项目 配置模块热更新hmr

    HRM并不是create-react-app专属的,提供一篇博客介绍hrm http://chrisshepherd.me/posts/adding-hot-module-reloading-to-c ...

  5. Linux系统中ElasticSearch搜索引擎安装配置Head插件

    近几篇ElasticSearch系列: 1.阿里云服务器Linux系统安装配置ElasticSearch搜索引擎 2.Linux系统中ElasticSearch搜索引擎安装配置Head插件 3.Ela ...

  6. C++ 学习笔记之——STL 库 vector

    vector 是一种顺序容器,可以看作是可以改变大小的数组. 就像数组一样,vector 占用连续的内存地址来存储元素,因此可以像数组一样用偏移量来随机访问,但是它的大小可以动态改变,容器会自动处理内 ...

  7. dice2win

    触发交易 转0个 https://etherscan.io/tx/0x784e80167353a886183106cbe3bd15e614cafdb5d6885ccd101177aa0f937a36 ...

  8. metamask注记词

    leaf orbit poet zebra toy day put dinosaur review cool pluck throw(m) 一个钱包地址 里面有多个账号 菲苾代表了不同网络

  9. HDU 1250 Hat's Fibonacci(高精度)

    Problem Description A Fibonacci sequence is calculated by adding the previous two members the sequen ...

  10. Dom的样式操作和属性操作

    如果说web的研究对象是html和css,那么整个dom结构,包含html树和dom树的dom结构才是研究对象,而在整个页面呈现上面,js起到的作用则是异步的用户行为. 按照上面整个思路,获取dom元 ...