POJ3469 Dual Core CPU (min cut)

Source: Internet
Author: User

The smallest cut of vivid image.

1#include <cstdio>2#include <cstring>3#include <queue>4#include <algorithm>5 using namespacestd;6 #defineINF (1&LT;&LT;30)7 #defineMAXN 22228 #defineMAXM 8888889 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 () { - 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) { theflow+=; -                      for(u=pre[v]; V!=vs; v=u,u=Pre[u]) { $edge[cur[u]].flow+=; theedge[cur[u]^1].flow-=; the                     } the                     //Aug=-1; theaug=INF; -                 } in                  Break; the             } the         } About         if(flag)Continue; the         intMinlevel=NV; the          for(intI=head[u]; i!=-1; I=Edge[i].next) { the             intv=edge[i].v; +             if(Edge[i].cap!=edge[i].flow && level[v]<minlevel) { -Minlevel=Level[v]; thecur[u]=i;Bayi             } the         } the         if(--gap[level[u]]==0) Break; -level[u]=minlevel+1; -gap[level[u]]++; theu=Pre[u]; the     } the     returnflow; the } - intMain () { the     intn,m,a,b,c; thescanf"%d%d",&n,&m); theXss0; vt=n+1; nv=vt+1;94memset (head,-1,sizeof(head)); the      for(intI=1; i<=n; ++i) { thescanf"%d%d",&a,&b); the Addedge (vs,i,a);98 Addedge (i,vt,b); About     } -      while(m--){101scanf"%d%d%d",&a,&b,&c);102 Addedge (a,b,c);103 Addedge (b,a,c);104     } theprintf"%d", ISAP ());106     return 0;107}

POJ3469 Dual Core CPU (min cut)

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.