POJ3184 Ikki ' s Story i-road reconstruction (Max Stream)

Source: Internet
Author: User

Once the maximum flow is calculated, the capacity of all the edges of the full stream is +1, and then the augmented path is found.

1#include <cstdio>2#include <cstring>3#include <queue>4#include <algorithm>5 using namespacestd;6 #defineINF (1&LT;&LT;30)7 #defineMAXN 5558 #defineMAXM 111119 Ten structedge{ One     intV,cap,flow,next; A }EDGE[MAXM]; - intVs,vt,ne,nv; - intHEAD[MAXN]; the  - voidAddedge (intUintVintcap) { -Edge[ne].v=v; Edge[ne].cap=cap; edge[ne].flow=0; -Edge[ne].next=head[u]; head[u]=ne++; +Edge[ne].v=u; edge[ne].cap=0; edge[ne].flow=0; -EDGE[NE].NEXT=HEAD[V]; head[v]=ne++; + } A  at intLEVEL[MAXN]; - intGAP[MAXN]; - voidBFs () { -memset (level,-1,sizeof(level)); -Memset (Gap,0,sizeof(GAP)); -level[vt]=0; ingap[level[vt]]++; -queue<int>que; to Que.push (VT); +      while(!Que.empty ()) { -         intu=Que.front (); Que.pop (); the          for(intI=head[u]; i!=-1; I=Edge[i].next) { *             intv=edge[i].v; $             if(level[v]!=-1)Continue;Panax Notoginsenglevel[v]=level[u]+1; -gap[level[v]]++; the Que.push (v); +         } A     } the } +  - intPRE[MAXN]; $ intCUR[MAXN]; $ intISAP (BOOLstatue) { - BFS (); -memset (pre,-1,sizeof(pre)); thememcpy (Cur,head,sizeof(head)); -     intu=pre[vs]=vs,flow=0, aug=INF;Wuyigap[0]=NV; the      while(level[vs]<NV) { -         BOOLflag=false; Wu          for(int&i=cur[u]; i!=-1; I=Edge[i].next) { -             intv=edge[i].v; About             if(Edge[i].cap!=edge[i].flow && level[u]==level[v]+1){ $flag=true; -pre[v]=u; -u=v; -                 //aug= (Aug==-1?edge[i].cap:min (Aug,edge[i].cap)); AAug=min (aug,edge[i].cap-edge[i].flow); +                 if(v==VT) { the                     if(Statue&&aug)return 1; -flow+=; $                      for(u=pre[v]; V!=vs; v=u,u=Pre[u]) { theedge[cur[u]].flow+=; theedge[cur[u]^1].flow-=; the                     } the                     //Aug=-1; -aug=INF; in                 } the                  Break; the             } About         } the         if(flag)Continue; the         intMinlevel=NV; the          for(intI=head[u]; i!=-1; I=Edge[i].next) { +             intv=edge[i].v; -             if(Edge[i].cap!=edge[i].flow && level[v]<minlevel) { theMinlevel=Level[v];Bayicur[u]=i; the             } the         } -         if(--gap[level[u]]==0) Break; -level[u]=minlevel+1; thegap[level[u]]++; theu=Pre[u]; the     } the     returnflow; - } the intMain () { the     intn,m,a,b,c; thescanf"%d%d",&n,&m);94Xss0; vt=n-1; Nv=n; Ne=0; thememset (head,-1,sizeof(head)); the      while(m--){ thescanf"%d%d%d",&a,&b,&c);98 Addedge (a,b,c); About     } -ISAP (0);101     intCnt=0;102      for(intI=0; i<ne; i+=2){103         if(EDGE[I].FLOW!=EDGE[I].CAP)Continue;104++Edge[i].cap; the         if(ISAP (1)) ++CNT;106--Edge[i].cap;107     }108printf"%d", CNT);109     return 0; the}

POJ3184 Ikki ' s Story i-road reconstruction (Max Stream)

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.