[Bzoj2055]80 people around the world [network flow, upper and lower bound network flow]

Source: Internet
Author: User

Manual drawing of the whole picture, it is understood,

1#include <bits/stdc++.h>2 3 #defineINF 0x3f3f3f3f4 5 using namespacestd;6 7template<Const int_n,Const int_m>8 structEdge9 {Ten     structEdge_base {intTo,next,w,c; }E[_M];intCnt,p[_n]; One Edge () {clear ();} A     voidClear () {cnt=1, Memset (P,0,sizeof(p)); } -     voidInsertConst intXConst intYConst intZConst intZZ) -{e[++cnt].to=y; e[cnt].next=p[x]; e[cnt].w=z; e[cnt].c=zz; p[x]=cnt;return ; } the     voidLinkConst intXConst intYConst intZConst intZZ) -{Insert (X,Y,Z,ZZ); Insert (Y,x,0,-ZZ); } -     intStartConst intx) {returnp[x];} -edge_base&operator[](Const intx) {returne[x];} + }; -  + intn,m,dis[ About],cost; A intcur[ About],sss,ttt,ss,tt; at BOOLvisited[ About]; -edge< About,510000>e; -  - BOOLSPFA (Const intS) - { -     inti,t,temp; inqueue<int>Q; -memset (Dis,0x3f,sizeof(Dis)); todis[s]=0; +visited[s]=true; - Q.push (S); the      while(!q.empty ()) *     { $t=Q.front (), Q.pop ();Panax Notoginsengvisited[t]=false; -          for(I=e.start (t); i;i=e[i].next) the         { +temp=e[i].to; A             if(E[I].W && dis[t]+e[i].c<Dis[temp]) the             { +dis[temp]=dis[t]+e[i].c; -                 if(!Visited[temp]) $                 { $visited[temp]=true; - Q.push (temp); -                 } the             } -         }Wuyi     } the     returndis[ttt]!=0x3f3f3f3f; - } Wu  - intDfs (Const intSConst intBK) About { $     if(S==TTT)returnBK; -visited[s]=true; -     intrest=BK; -      for(int&i=cur[s];i;i=e[i].next) A     { +         if(!visited[e[i].to] && dis[s]+e[i].c==dis[e[i].to] &&E[I].W) the         { -             intflow=Dfs (E[i].to,min (REST,E[I].W)); $cost+=flow*e[i].c; thee[i].w-=flow; thee[i^1].w+=flow; the             if((Rest-=flow) <=0) Break; the         } -     } in     if(bk==rest) dis[s]=0x3f3f3f3f; thevisited[s]=false; the     returnbk-rest; About } the  the intZkw () the { +     intflow=0; -      while(SPFA (SSS)) the     {Bayimemcpy (CUR,E.P,sizeof(cur)); theFlow+=dfs (SSS,0x3f3f3f3f); the     } -     returnCost ; - } the  the intMain () the { the     inti,j,a,x; -  thescanf"%d%d",&n,&m); the  thess=n<<1|1, tt=ss+1, sss=tt+1, ttt=sss+1;94      for(i=1; i<=n;++i) the     { thescanf"%d",&a); theE.link (Sss,i+n,a,0);98E.link (I,ttt,a,0); AboutE.link (I+n,tt,inf,0); -E.link (Ss,i,inf,0);101     }102     103      for(i=1; i<=n;++i) for(j=i+1; j<=n;++j)104     { thescanf"%d",&x);106         if(x==-1)Continue;107E.link (i+n,j,inf,x);108     }109  theE.link (Tt,ss,m,0);111  theprintf"%d\n", Zkw ());113     return 0; the}

[bzoj2055]80 people around the world [network flow, upper and lower bound network 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.