Minimum cut template zoj2753

Source: Internet
Author: User

Max flow = = Min cut

///Graph-Free minimum cut template node numbering starting from 1#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespacestd;intn,m;intCNT =0;intmp[510][510] ;intv[510], dis[510], vis[510] ;intStoer_wagner (intN) {    intAns =0x3f3f3f3f ;  for(intI=1; i<=n;i++) {V[i]=i; }     while(n>1){        intK,pre =0;///pre represents the point at which the collection was previously joinedmemset (Vis,0,sizeofvis); memset (DIS,0,sizeofdis);  for(intI=1; I<n; i++) {k= -1 ;  for(intj=1; j<n;j++){                if(!Vis[v[j]]) {Dis[v[j]]+=Mp[v[pre]][v[j]]; if(k==-1|| Dis[v[k]] <Dis[v[j]]) {k=J; } }} cout<<k<<" "<<n<<Endl; VIS[V[K]]=1; if(i = = n1) {ans=min (ans, dis[v[k]]);  for(intj=0; j<n;j++) {///merging K into the pre, corresponding edge rights are also mergedmp[v[pre]][v[j]]+=Mp[v[k]][v[j]]; Mp[v[j]][v[pre]]+=Mp[v[k]][v[j]]; } V[k]= v[--N]; } Pre=K; }    }    returnans;}intMain () { while(~SCANF ("%d%d",&n,&m)) {memset (MP,0,sizeofMP);  for(intI=0; i<m;i++){            intu,v,w; scanf ("%d%d%d",&u,&v,&W); MP[U][V]+=W; Mp[v][u]+=W; } printf ("%d\n", Stoer_wagner (n)); }    return 0;}

Minimum cut template zoj2753

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.