bzoj3396[usaco2009 jan]total Flow Flow *

Source: Internet
Author: User

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 *

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.