A minimum cut stoer_wagner algorithm for non-direction graphs

Source: Internet
Author: User

1 Const intMax_n =1;2 intG[max_n][max_n];3 intV[max_n];//V[i] represents the vertex to which node I is merged4 intW[max_n];//define W (a,x) =∑w (v[i],x), V[i]∈a5 BOOLVisited[max_n];//used to mark whether the point has been added to a collection6 7 intStoer_wagner (intN)8 {9     intMin_cut =inf;Ten      for(inti =0; I < n; ++i) One     { AV[i] = i;//the initial is not merged, all of which represent the node itself -     } -  the      while(N >1) -     { -         intPre =0;//The pre is used to indicate the point before adding a set (a point added before T) -Memset (visited,0,sizeof(visited)); +Memset (W,0,sizeof(w)); -          for(inti =1; I < n; ++i) +         { A             intK =-1; at              for(intj =1; J < N; ++J)//Select W (a,x) largest point x in V-a to join the collection -             { -                 if(!Visited[v[j]]) -                 { -W[V[J]] + =G[v[pre]][v[j]]; -                     if(k = =-1|| W[v[k]] <W[v[j]]) in                     { -K =J; to                     } +                 } -             } the  *Visited[v[k]] =true;//mark the point X has joined a set $             if(i = = N-1)//If | a|=| V| (all points are added a), endPanax Notoginseng             { -                 Const ints = v[pre], t = v[k];//make the second-to-last point (V[pre]) to S, and the final point with a (V[k]) is T themin_cut = min (min_cut, w[t]);//The s-t min Cut is w (a,t), updated with its min_cut +                  for(intj =0; J < N; ++J)//contract (S, T) A                 { theG[S][V[J]] + =G[v[j]][t]; +G[v[j]][s] + =G[v[j]][t]; -                 } $V[K] = V[--n];//Delete the last point (that is, delete T and merge T into s) $             } -             //Else Continue -Pre =K; the         } -     }Wuyi     returnMin_cut; the}

A minimum cut stoer_wagner algorithm for non-direction graphs

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.