无源汇的最小费可行流。
需要清洁的管道下界为1,不需要清洁的管道下界为0。
可重复经过的管道上界为正无穷,不可重复经过的管道上界为1。
然后建图直接跑最小费用流。
AC代码:
#include<iostream>
#include<queue>
#include<string.h>
using namespace std;
const int maxn = 233;
const int inf = 0x3f3f3f3f;
struct node{
int u,v,f,w,nxt;
node(){};
node(int a,int b,int c,int d,int e):u(a),v(b),f(c),w(d),nxt(e){}
}e[maxn*maxn];
int cnt = 0;
int head[maxn];
void add(int u,int v,int f,int w){
e[cnt] = node(u,v,f,w,head[u]);
head[u] = cnt++;
e[cnt] = node(v,u,0,-w,head[v]);
head[v] = cnt++;
}
int st,ed,E,ex;
int n,m;
int du[maxn];
int sum;
int num = 0;
void init(){
scanf("%d%d",&n,&m);
st = 0;ed = n + 1;
ex = n + 2;
cnt = 0;
sum = 0;
num = 0;
memset(head,-1,ex<<2);
memset(du,0,ex<<2);
while(m--){
int u,v;