Summary of global minimum cut learning

Source: Internet
Author: User

The global minimum cut means to take s and T in an all-in-one graph, and to find the minimum value of minimum cut.

There is also a description of the minimum cost of deleting edges in undirected graphs so that they do not connect

Of course, this topic can be solved by splitting + minimum cut

But the complexity of time is around O (n^4).

A better solution can be solved in the time complexity of O (n^3)

The practice is this:

First, for any two points in the graph s->t

Either S and T are not the answer in a set, the answer is clearly the smallest cut of s and T

Otherwise s and T in a set, we can shrink s and t into a point, it is not difficult to prove that this is equivalent

We simulate this process, each time the S and T run the minimum cut, the time complexity is probably the same as the division + minimum cut almost Owo

But we notice that both S and T are either, that is, we just need to ask for a set of solutions.

This gives you a construction algorithm:

1, at the beginning a set is empty, we take a little to join a set of

2, the definition W (a,x) represents a set of all points to x Benquan and

3, each time looking for W (a,x) The largest point (the same word whichever), add a set and update the other W value

4, the last two points added are S and T, the minimum cut is the last addition of W (A,T)

This process directly simulates an O (n^2), plus a pinch point for up to O (n) times

So the total time complexity O (n^3) can be optimized with heaps, but dense graphs run very slowly and slowly

Bzoj 3345

 #include <cstdio> #include <cstring> #include <cstdlib> #include <iostream> #include < Algorithm> using namespace std; const int Maxn=510;const int Oo=0x7fffffff;int n,m,u,v,d;int s,t,cut;int f[maxn][maxn];int w[maxn];bool com[maxn],vis[ MAXN]; void Get_ans () {cut=oo;    S=t=-1;    memset (vis,false,sizeof (VIS));    Memset (W,0,sizeof (w));        for (int i=1;i<=n;++i) {int mx=-oo,tmp;            for (int j=1;j<=n;++j) {if (!com[j]&&!vis[j]&&w[j]>mx) {mx=w[j];tmp=j;        }} if (t==tmp) return; s=t;        t=tmp;        Cut=mx;vis[tmp]=true;    for (int j=1;j<=n;++j) if (!com[j]&&!vis[j]) w[j]+=f[tmp][j]; }return;}    int get_sw () {memset (com,false,sizeof (COM));    int Ans=oo;        for (int i=1;i<n;++i) {Get_ans ();        Ans=min (Ans,cut);        if (ans==0) return 0;        Com[t]=true;        for (int j=1;j<=n;++j) {if (!com[j]) {f[s][j]+=f[t][j];f[j][s]+=f[j][t];}  }  }return ans;}    int main () {scanf ("%d%d", &n,&m);    memset (F,0,sizeof (f));        for (int i=1;i<=m;++i) {scanf ("%d%d%d", &u,&v,&d);    F[u][v]+=d;f[v][u]+=d;    } printf ("%d\n", GET_SW ()); return 0;}

HDU 3691

Notice here that S is given by the

But it's not hard to see that there are no eggs, the answer is the global minimum cut

Because the final global minimum cut must have a T and s not belong to a set Owo

And because it is a global minimum cut, the minimum cut of this set of s->t is the global minimum cut

#include <cstdio> #include <cstring> #include <cstdlib> #include <iostream> #include < Algorithm>using namespace Std;typedef long long ll;const int maxn=310;const LL oo=1ll<<60;int n,m,k;int u,v,w;in T s,t; LL Ans,cut; LL F[MAXN][MAXN];    LL w[maxn];bool com[maxn],vis[maxn];void Read (int &num) {Num=0;char Ch=getchar (); while (ch< '! ')    Ch=getchar (); while (ch>= ' 0 ' &&ch<= ' 9 ') num=num*10+ch-' 0 ', Ch=getchar ();} void Get_ans () {cut=oo;    S=t=-1;    memset (vis,false,sizeof (VIS));    memset (w,0,sizeof (W));        for (int i=1;i<=n;++i) {LL mx=-oo;int tmp;        for (int j=1;j<=n;++j) {if (!com[j]&&!vis[j]&&w[j]>mx) {mx=w[j];tmp=j;}        } if (t==tmp) return; s=t;        t=tmp;        Cut=mx;vis[tmp]=true;        for (int j=1;j<=n;++j) {if (!com[j]&&!vis[j]) {w[j]+=f[tmp][j];} }}return;}    LL get_sw () {ans=oo;memset (com,0,sizeof (COM)); for (int i=1;i<n;++i) {Get_ans ();       Ans=min (Ans,cut);        if (ans==0) return ans;        Com[t]=true;        for (int j=1;j<=n;++j) {if (!com[j]) {f[s][j]+=f[t][j];f[j][s]+=f[j][t];} }}return ans;        int main () {while (scanf ("%d%d%d", &n,&m,&k) ==3) {if (!n&&!m&&!k) break;        memset (F,0,sizeof (f));            for (int i=1;i<=m;++i) {read (u); Read (v); Read (w);        F[u][v]+=w;f[v][u]+=w;    } printf ("%d\n", GET_SW ()); }return 0;}

  

Summary of global minimum cut learning

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.