Gao Tianyu's Isap template, don't explain it ...
#include <queue>#include<cstdio>#include<cctype>#include<cstring>#include<algorithm>using namespacestd;Const intinf=1E9;intn,m,point[203],nxt[403],v[403],c[403],cnt=0;intdeep[203],num[203],cur[203],lastedge[203];BOOLvis[203];inlineintGetint () {CharC while(!isdigit (C=getchar ()));inta=c-'0'; while(IsDigit (C=getchar ())) a=a*Ten+c-'0';returnA;} InlinevoidInsect (intXintYintZ) {nxt[cnt]=point[x];p oint[x]=cnt;v[cnt]=y;c[cnt]=z;cnt++;} InlinevoidBFsintt) { for(intI=1; i<=n;++i) deep[i]=N; memset (Vis,0,sizeof(VIS)); Queue<int>q; vis[t]=1; Q.push (t); deep[t]=0; while(!Q.empty ()) { intnow=Q.front (); Q.pop (); for(inttmp=point[now];tmp!=-1; tmp=nxt[tmp])if((vis[v[tmp]]==0) && (c[tmp^1]!=0) ) {vis[v[tmp]]=1; Q.push (V[tmp]); DEEP[V[TMP]]=deep[now]+1; }}}inlineintAddflow (intSintt) { intans=inf,now=T; while(now!=s) {ans=min (Ans,c[lastedge[now]]); now=v[lastedge[now]^1]; }now=T; while(now!=s) {C[lastedge[now]]-=ans; C[lastedge[now]^1]+=ans; now=v[lastedge[now]^1]; }returnans;} InlineintISAP (intSintt) { intans=0, now=s; bfs (t); for(intI=1; i<=n;++i) num[deep[i]]++,cur[i]=Point[i]; while(deep[s]<N) { if(now==t) {ans+=Addflow (s,t); now=s; }BOOLHas_find=0; for(inttmp=cur[now];tmp!=-1; tmp=Nxt[tmp]) { intu=V[tmp]; if((deep[u]+1==deep[now]) && (c[tmp]!=0) ) {Has_find=1; Cur[now]=tmp; Lastedge[u]=tmp; now=T; Break; } } if(has_find==0){ intminn=n-1; for(inttmp=point[now];tmp!=-1; tmp=nxt[tmp])if(c[tmp]!=0) minn=min (minn,deep[v[tmp]]); if(--num[deep[now]]==0) Break; Num[deep[now]=minn+1]++; Cur[now]=Point[now]; if(now!=s) now=v[lastedge[now]^1]; } }returnans;}intMain () {memset (point,-1,sizeof(point)); memset (NXT,-1,sizeof(NXT)); M=getint (); n=Getint (); for(intI=1; i<=m;++i) { intX=getint (), Y=getint (), z=Getint (); Insect (x, y, z); Insect (y,x,0); }printf ("%d\n", ISAP (1, N));return 0;}
"Codevs 1993" Lawn Drainage isap template problem