改f上一篇文章的时候顺便学会了求最小割边集的方法,虽然用到上一题上是错的,但是把这个方法也先总结一下;
先跑一遍最大流,在残余流量里从s开始dfs凡事能从s开始能流到的点标记为1,其他的标记为0,起点为1终点为0的边集是一组最小割边集。
cpp:
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <bitset>
#include <queue>
using namespace std;
#define maxn 10010
#define INF 1e9
struct Edge{
int from,to,cap,flow;
};
struct Dinic{
int n,m,s,t;
vector<Edge> edges;
vector<int> G[maxn],g[maxn];
vector<Edge> ed;
bool vis[maxn] ;
int d[maxn];
int cur[maxn];
int un[maxn];
void add(int a,int b){
edges.push_back((Edge){a,b,1,0});
edges.push_back((Edge){b,a,0,0});
m=edges.size();
G[a].push_back(m-2);
G[b].push_back(m-1);
}
bool bfs(){
memset(vis,0,sizeof(vis));
queue