The standard big petition template, the code is simple but because the efficiency is not high, therefore is not commonly used, is this
1#include <stdio.h>2#include <string.h>3#include <queue>4#include <vector>5#include <algorithm>6 using namespacestd;7 Const intmaxm= Max+5;8 Const intinf=0x3f3f3f3f;9 Ten structedge{ One int from, to,c,f; AEdgeintAintBintMintN): from(a), to (b), C (M), f (n) {} - }; - the structek{ - intn,m; -Vector<edge>e; -vector<int>G[MAXM]; + intA[MAXM]; - intP[MAXM]; + A voidInitintN) { at for(intI=0; i<n+3; i++) g[i].clear (); - e.clear (); - } - - voidAddint from,intTo,intc) { -E.push_back (Edge ( from, To,c,0)); inE.push_back (Edge to, from,0,0)); -m=e.size (); tog[ from].push_back (M-2); +G[to].push_back (M-1); - } the * intMfintSintt) { $ intf=0;Panax Notoginseng while(1){ -Memset (A,0,sizeof(a)); thequeue<int>Q; + Q.push (s); Aa[s]=INF; the while(!Q.empty ()) { + intu=Q.front (); - Q.pop (); $ for(intI=0; I<g[u].size (); i++){ $Edge tmp=E[g[u][i]]; - if(!a[tmp.to]&&tmp.c>tmp.f) { -p[tmp.to]=G[u][i]; theA[tmp.to]=min (a[u],tmp.c-tmp.f); - Q.push (tmp.to);Wuyi } the } - if(A[t]) Break; Wu } - if(!a[t]) Break; About for(intI=t;i!=s;i=e[p[i]]. from){ $e[p[i]].f+=A[t]; -e[p[i]^1].f-=A[t]; - - } Af+=A[t]; + } the returnF; - } $};
Network Flow--Max stream ek template