~~~题面~~~

题解:

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

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. Entity Framework Core 导航属性 加载数据

    Loading Related Data https://docs.microsoft.com/en-us/ef/core/querying/related-data Eager loading me ...

  2. C#如何使用反射实现通过字符串创建类

    在做项目中碰到一个问题,就是如何在知道一个类的名字,如何创建这个类呢.做的一个小测试,直接贴代码了. using System; using System.Collections.Generic; u ...

  3. excell 导入 导出

    1.jar包 2.POIUtils工具类 package com.esstglobal.service.utils; import java.io.BufferedInputStream; impor ...

  4. PS 抠图和添加背景图

    1.打开需要抠的图--然后使用套索类工具,魔棒类工具,钢笔类工具均可选择需要扣的图片范围任何在Delete(如果抠反了可以进行反选Ctrl +shift+I) 2.然后把任一一张背景图直接拖到PS里面 ...

  5. OpenSUSE 11 安装Qt5.0,失败,失败,失败,留个坑,以后来填,万一实现了呢

    我又来无耻的写问题来了,这次还真的是没有解决,线留坑吧,万一以后实现了. 同样,这次也是以恶搞网友说听说想在open suse 上面安装5.0版本以后的Qt,自己折腾好几没有成功. 我一想,哎,这不是 ...

  6. (python)leetcode刷题笔记 01 TWO SUM

    1. Two Sum Given an array of integers, return indices of the two numbers such that they add up to a ...

  7. org.apache.spark.sql.functions汇总

    测试数据: id,name,age,comment,date 1,lyy,28,"aaa bbb",20180102020325 scala> var data = spar ...

  8. 【Linux 运维】linux系统查看版本信息

    查看linux系统版本信息: [root@kvm-host~]# cat /proc/version       (Linux查看当前操作系统版本信息)Linux version 3.10.0-514 ...

  9. 计蒜客蓝桥杯模拟赛 后缀字符串:STL_map+贪心

    问题描述 一天蒜头君得到 n 个字符串 si​,每个字符串的长度都不超过 10. 蒜头君在想,在这 n 个字符串中,以 si​ 为后缀的字符串有多少个呢? 输入格式 第一行输入一个整数 n. 接下来  ...

  10. Dictionary tabPage使用

    public override bool AccptChange() { //if (oldvalue == null || oldvalue.Count <= 0) //{ // return ...