This seems to be similar to the nature of the Ek algorithm, but a dfs, a bfs, generally seems to be better with bfs.
Program:
#include <iostream>#include<cstdio>#include<vector>#include<cstring>using namespacestd;structedge{int from, to,cap,flow,nod;}; Vector<edge>g[20000];ints,t;BOOLvis[20000];voidAddintUintVintW) {g[u].push_back (edge) {u,v,w,0, G[v].size ()}); G[v].push_back (edge) {v,u,0,0, G[u].size ()-1});}intDfsintNowintmaxx) { if(now==t)returnmaxx; vis[now]=true; for(intI=0; I<g[now].size (); i++) {edge e=g[now][i]; if((!vis[e.to]) && (e.cap>E.flow)) {intD=dfs (e.to,min (maxx,e.cap-e.flow)); if(d>0) {e.flow+=d; g[now][i]=e; G[e.to][e.nod].flow-=d; returnd; } } } return 0;}intmain () {intm,a,b,c,n; scanf ("%d%d%d%d",&n,&m,&s,&t); for(intI=1; i<=m;i++) {scanf ("%d%d%d",&a,&b,&c); Add (a,b,c); } intans=0; for (;;) {memset (vis,0,sizeofvis); intSum=dfs (s),210000000); if(sum==0) break; Ans+=sum; } printf ("%d\n", ans); return 0;}
Ford-fulkerson algorithm of "template" maximum flow