bzoj3396[usaco2009 Jan]total Flow Flow
Test instructions
The maximum flow of an annular graph is obtained. Number of sides ≤700.
Exercises
Tube it has no ring. Note that the node designator of the subject has both uppercase and lowercase letters.
Code:
1#include <cstdio>2#include <cstring>3#include <algorithm>4#include <queue>5 #defineInc (I,J,K) for (int i=j;i<=k;i++)6 #defineMAXN 1007 #defineINF 0X3FFFFFFF8 using namespacestd;9 Ten structe{intT,c,n;} es[maxn* the];intg[maxn],ess; One voidPeintFintTintc) { AEs[++ess]= (e) {t,c,g[f]}; g[f]=ess; Es[++ess]= (e) {f,0, G[t]}; g[t]=ess; -Es[++ess]= (e) {f,c,g[t]}; g[t]=ess; Es[++ess]= (e) {T,0, G[f]}; g[f]=ess; - } thequeue<int>q;intH[MAXN]; - BOOLBFsintSintt) { - while(!q.empty ()) Q.pop (); memset (h,-1,sizeof(h)); Q.push (s); h[s]=0; - while(!Q.empty ()) { + intx=Q.front (); Q.pop (); - for(intI=G[X];I;I=ES[I].N)if(es[i].c&&h[es[i].t]==-1) {h[es[i].t]=h[x]+1; Q.push (es[i].t);} + } A returnh[t]!=-1; at } - intDfsintXintTintf) { - if(x==t)returnFintu=0; - for(intI=G[X];I;I=ES[I].N)if(es[i].c&&h[es[i].t]==h[x]+1){ - intW=dfs (Es[i].t,t,min (F,ES[I].C)); F-=w; u+=W; -Es[i].c-=w; es[i^1].c+=w;if(f==0)returnu; in } - if(u==0) h[x]=-1;returnu; to } + intDinic (intSintt) { - intf=0; while(BFS (s,t)) F+=dfs (S,t,inf);returnF; the } * intS,t,n; $ intMain () {Panax Notoginsengscanf"%d", &n); ess=1; s=0; t='Z'-'A'; -Inc (I,1, N) {Charx[3],y[3];intZ scanf"%s%s%d", x,y,&z); PE (x[0]-'A', y[0]-'A', z);} theprintf"%d", Dinic (s,t));return 0; +}
20160908
bzoj3396[usaco2009 jan]total Flow Flow *