"Bzoj" "2502" cleaning the snow track

Source: Internet
Author: User

Network flow/upper and lower bound network flow

The least viable flow below the bounds ...

I am a SB, running the network stream is to run from the virtual source 0. Instead of s ...

Orz Hzwer

1 /**************************************************************2 problem:25023 User:tunix4 language:c++5 result:accepted6 time:3080 Ms7 memory:10652 KB8 ****************************************************************/9  Ten //Bzoj 2502 One#include <vector> A#include <cstdio> -#include <cstdlib> -#include <cstring> the#include <iostream> -#include <algorithm> - #defineRep (i,n) for (int i=0;i<n;++i) - #defineF (i,j,n) for (int i=j;i<=n;++i) + #defineD (i,j,n) for (int i=j;i>=n;--i) - using namespacestd; + intGetint () { A     intv=0, sign=1;CharCh=GetChar (); at      while(ch<'0'|| Ch>'9') {if(ch=='-') sign=-1; Ch=GetChar ();} -      while(ch>='0'&&ch<='9') {v=v*Ten+ch-'0'; Ch=GetChar ();} -     returnv*Sign ; - } -typedefLong LongLL; - Const intn=100010, m=500010, inf=~0u>>2; in /*******************tamplate********************/ - intN,m,ans; to structedge{intto,v;}; + structnet{ - Edge E[m]; the     inthead[n],next[m],cnt; *     voidInsintXintYintz) { $e[++cnt]=(Edge) {y,z};Panax NotoginsengNEXT[CNT]=HEAD[X]; head[x]=CNT; -     } the     voidAddintXintYintz) { +Ins (x, y, z); Ins (y,x,0); A     } the     intS,t,d[n],cur[n],q[m]; +     BOOLMklevel () { -         intL=0, r=-1; $F (I,0, T) d[i]=-1; $d[0]=0; q[++r]=0; -          while(l<=R) { -             intx=q[l++]; the              for(intI=head[x];i;i=Next[i]) -                 if(E[I].V && d[e[i].to]==-1){Wuyid[e[i].to]=d[x]+1; theq[++r]=e[i].to; -                 } Wu         } -         returnd[t]!=-1; About     } $     intDfsintXinta) { -         if(x==t)returnA; -         intflow=0; -          for(int&i=cur[x];i && flow<a;i=Next[i]) A             if(E[I].V && d[e[i].to]==d[x]+1){ +                 intF=dfs (E[i].to,min (e[i].v,a-flow)); thee[i].v-=F; -e[i^1].v+=F; $flow+=F; the             } the         if(!flow) d[x]=-1; the         returnflow; the     } -     voidDinic () { in          while(Mklevel ()) { theF (I,0, T) cur[i]=Head[i]; theAns+=dfs (0, INF); About         } the     } the     int inch[N]; the     voidinit () { +N=getint (); Cnt=1; m=0; -F (I,1, N) { the             intx=getint (), y;BayiF (J,1, X) { theY=getint (); m++; theAdd (i,n+2*m-1, INF); -Add (n+2*m,y,inf); -             } the         } thes=n+m+m+1; t=s+1; ans=0; theF (I,1, M) { theAdd (n+2*i-1, n+2*i,inf); -             inch[n+2*i-1]--;inch[n+2*i]++; the         } theF (I,1, N) Add (s,i,inf); theF (i,n+1, n+m+m)94             if(inch[i]>0) Add (0Iinch[i]); the             ElseAdd (i,t,-inch[i]); the          for(intI=1;; i++){ theAdd0S1);98 dinic (); About             if(ans==m) {printf ("%d\n", i); Break;} -         }101     }102 }g1;103 intMain () {104 #ifndef Online_judge theFreopen ("Input.txt","R", stdin);106 //freopen ("Output.txt", "w", stdout);107     #endif108 g1.init ();109     return 0; the}
View Code

"Bzoj" "2502" cleaning the snow track

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.