关于费用流
  • 板块学术版
  • 楼主hgckythgcfhk
  • 当前回复4
  • 已保存回复4
  • 发布时间2024/2/24 11:36
  • 上次更新2024/2/24 14:55:19
查看原帖
关于费用流
692274
hgckythgcfhk楼主2024/2/24 11:36

我理解的是要先把最大流的 bfs 换成 spfa 或者 预处理+dij,但是像这种没有 bfs 的 ISAP 怎么办,是否必须先背有 bfs 的版本,或者先背 dinic 或者 EK?

这是我现在背的模板,为防止歧义,包括宏定义一起放上

#include <bits/stdc++.h>
#define cit const register unsigned
#define open ios::sync_with_stdio(0),cin.tie(0),cout.tie(0),freopen("1.in","r",stdin),freopen("1.out","w",stdout)
#define ll long long
#define int register signed
#define void inline void
#define cle(a) memset(a,0,sizeof a)
#define min(a,b) ((a)<(b)?(a):(b))
using namespace std;constexpr unsigned N=1e3+2,inf=~0;
struct A{unsigned v,inv;unsigned ll f,w;};vector<A>a[N];void add(cit u,cit v,cit ll w){
	a[u].emplace_back(A{v,a[v].size()-0,0,w});
	a[v].emplace_back(A{u,a[u].size()-1,0,0});}
namespace ISAP{unsigned ll c[N],d[N],g[N],s,t,n;
	inline unsigned ll dfs(cit u,cit ll r){if(u==t||!r)return r;int v;
		int ll w,f,h,b=0;for(;c[u]<a[u].size();++c[u]){auto&e=a[u][c[u]];
		v=e.v,w=e.w,f=e.f;if(d[u]==d[v]+1&&(h=dfs(v,min(w-f,r-b)))){
			b+=h,e.f+=h,a[v][e.inv].f-=h;if(b==r||d[s]>=n)return b;	
		}}if(!(--g[d[u]]))d[s]=n;g[++d[u]]++;return b;}
	inline unsigned ll aa(cit ts,cit tt,cit tn){int ll ans=0;s=ts,t=tt,n=tn;
		cle(d),cle(g);while(d[s]<n)cle(c),ans+=dfs(s,inf);return ans;}}

或者说,有没有和这个模板一样码量 1k 左右或更小且能用 vector 做的费用流算法

2024/2/24 11:36
加载中...