#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=1e5+10,M=2e5+10,Inf=1e9;
namespace Flow{
const ll INF=1e18;
const int V=N,E=M*2+N*2*2;
int s,t,kk,head[V],cur[V],vis[V];
ll d[V];
struct edges{
int to,c,w,nex;
}edge[E];
void init(int x,int y){
s=x,t=y,kk=1;
fill(head+s,head+1+t,0);
}
void add(int u,int v,int c,int w){
edge[++kk]={v,c,w,head[u]},head[u]=kk;
edge[++kk]={u,0,-w,head[v]},head[v]=kk;
}
bool bfs(){
queue<int>q;
copy(head+s,head+1+t,cur+s);
fill(d+s,d+1+t,INF),d[s]=0;
q.push(s);
for(int u;!q.empty();){
u=q.front(),q.pop();
for(int i=head[u];i;i=edge[i].nex){
int v=edge[i].to,c=edge[i].c,w=edge[i].w;
if(c&&d[v]>d[u]+w){
d[v]=d[u]+w,q.push(v);
}
}
}
return d[t]<INF;
}
ll sum;
int dfs(int u,int lim=Inf){
if(u==t)return lim;
vis[u]=1;
int flow=0;
for(int i=cur[u];i&&flow<lim;i=edge[i].nex){
cur[u]=i;
int v=edge[i].to,c=edge[i].c;
if(!c||d[v]!=d[u]+edge[i].w||vis[v])continue;
int f=dfs(v,min(lim-flow,edge[i].c));
if(!f)d[v]=INF;
edge[i].c-=f,edge[i^1].c+=f,flow+=f;
sum+=1ll*f*edge[i].w;
}
vis[u]=0;
return flow;
}
int dinic(){
int flow=0;
for(;bfs();)flow+=dfs(s);
return flow;
}
}
int main(){
return 0;
}
标签:head,const,--,ll,zhengjun,int,edge,kk,模板
From: https://www.cnblogs.com/A-zjzj/p/17752018.html