"Min cut" "Dinic" "Strong Unicom" bzoj1797 [ahoi2009]mincut min. cut

Source: Internet
Author: User

Conclusion:

Satisfies the condition one: when the beginning and the end point of an edge is not in a strong unicom component of the residual quantity network. and full stream.

Satisfies the condition two: when the beginning and the end point of an edge are in the strong unicom component of S and T respectively. and full stream. 、

Online a lot of.

1#include <cstdio>2#include <cstring>3#include <vector>4#include <algorithm>5#include <queue>6 using namespacestd;7 #defineINF 21474836478 #defineMAXN 40119 #defineMAXM 120101Ten intV[MAXM],CAP[MAXM],EN,FIRST[MAXN],NEXT[MAXM]; One intd[maxn],cur[maxn],cmp[maxn],sum; A BOOLVIS[MAXN]; -queue<int>Q; -vector<int>vs; the intn,m,s,t,a,b,c; - voidInit_dinic () {memset (first,-1,sizeof(first)); en=0;} - voidAddedge (Const int&u,Const int&v,Const int&W) -{v[en]=v; cap[en]=w; next[en]=first[u]; first[u]=en++; +V[en]=u; NEXT[EN]=FIRST[V]; first[v]=en++;} - BOOLBFS () + { Amemset (d,-1,sizeof(d)); Q.push (S); d[s]=0; at      while(!q.empty ()) -       { -         intu=Q.front (); Q.pop (); -          for(inti=first[u];i!=-1; i=Next[i]) -           if(d[v[i]]==-1&&Cap[i]) -             { ind[v[i]]=d[u]+1; - Q.push (V[i]); to             } +       } -     returnd[t]!=-1; the } * intDfsintUinta) $ {Panax Notoginseng     if(u==t | |!a)returnA; -     intflow=0, F; the      for(int&i=cur[u];i!=-1; i=Next[i]) +       if(d[u]+1==d[v[i] && (f=Dfs (v[i],min (a,cap[i )))) A         { theCap[i]-=f; cap[i^1]+=F; +Flow+=f; A-=f;if(!a) Break; -         } $     if(! Flow) d[u]=-1; $     returnFlow; - } - voidMax_flow () the { -      while(BFS ())Wuyi       { thememcpy (Cur,first, (n+5)*sizeof(int)); -          while(Dfs (S,inf)); Wu       } - } About voidDfsintU) $ { -vis[u]=1; -      for(inti=first[u];i!=-1; I=next[i])if(cap[i]&& (!Vis[v[i])) DFS (V[i]); - Vs.push_back (U); A } + voidDFS2 (intU) the { -cmp[u]=sum; $      for(inti=first[u];i!=-1; I=next[i])if(cap[i^1]&& (!Cmp[v[i])) DFS2 (V[i]); the } the voidSCC () the { the      for(intI=1; i<=n;i++)if(!Vis[i]) DFS (i); -vector<int>::iterator It=vs.end (); --it; in      for(;; --it) the       { the         if(!cmp[*it]) {++sum; DFS2 (*it);} About         if(It==vs.begin ()) Break; the       } the } the intMain () + { -scanf"%d%d%d%d",&n,&m,&s,&T); Init_dinic (); the      for(; m;--m)Bayi       { thescanf"%d%d%d",&a,&b,&C); the Addedge (a,b,c); -       } - Max_flow (); SCC (); the      for(intI=0; i<en;i+=2) theprintf"%d%d\n", (!cap[i]) &&cmp[v[i+1]]!=cmp[v[i]], (!cap[i]) &&cmp[v[i+1]]==cmp[s]&&cmp[v[i]]==cmp[t]); the     return 0; the}

"Min cut" "Dinic" "Strong Unicom" bzoj1797 [ahoi2009]mincut 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.