POJ3084 Panic (min cut)

Source: Internet
Author: User

The minimum cost of separating a point from a certain point, of course, is to think of the smallest cut. Specifically how to build a diagram, you can draw a simple situation, and then clear:

0 to 1 uncontrolled, establishes 0->1 capacity for the edge of the INF;

1 to 0 is controlled by a control panel on the 1 side, establishing an edge of 1->0 capacity of 1.

1#include <cstdio>2#include <cstring>3#include <queue>4#include <algorithm>5 using namespacestd;6 #defineINF (1&LT;&LT;30)7 #defineMAXN 228 #defineMAXM 88889 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     intt,n,a,b; the     Chars[ One]; thescanf"%d",&t);94      while(t--){ thescanf"%d%d",&n,&VT); theVs=n; nv=n+1; Ne=0; thememset (head,-1,sizeof(head));98          for(intI=0; i<n; ++i) { Aboutscanf"%s", s); -             if(s[0]=='I') Addedge (vs,i,inf);101scanf"%d",&a);102              while(a--){103scanf"%d",&b);104 Addedge (i,b,inf); theAddedge (B,i,1);106             }107         }108         intres=Isap ();109         if(res>10000000) puts ("PANIC BREACH"); the         Elseprintf"%d\n", res);111     } the     return 0;113}

POJ3084 Panic (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.