UVA 1660 Cable TV Network [min Cut] [connectivity of graph] [Split Point]

Source: Internet
Author: User

Cable TV Network
Time limit:3000ms 64bit IO Format:%lld &%llu


The point connectivity of undirected graphs is obtained, that is to say, to find the minimum cut of any two points.
But considering s set and T set, the middle is connected by several edges, these edges are the smallest cuts of s to T, assuming that this is the answer, then finding that there is no need to enumerate all the points, but to fix a point, and enumerate another point to ensure that at least one of the situations is a bit in the S set at the other point in the T set.
Then because one point can only pass once, then the side with the capacity of 1 is connected after the split, then the other edges are connected to the INF.
Note that each time you want to generate an INF for the source and meeting point capacity, you cannot cut this edge.
The paper also mentioned that another method, can find the original image of the minimum spanning tree to solve, for this problem is not necessary.
The following is a bit of code for the enumeration:

#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath > #include <vector> #include <queue> #include <stack> #include <map> #include <string> include<iomanip> #include <ctime> #include <climits> #include <cctype> #include <algorithm
> Using namespace std;
    inline int read (int &x) {x=0;
    Char ch= ' n '; int flag=1; while (ch< ' 0 ' | |
        Ch> ' 9 ') {Ch=getchar ();
        if (ch==eof) return-1;
    if (ch== '-') {Flag=-1;ch=getchar (); break;}
        while (ch>= ' 0 ' &&ch<= ' 9 ') {x*=10;
        x+=ch-' 0 ';
    Ch=getchar ();
    } X*=flag;
return 1;
const int inf=0x3f3f3f3f;
const int maxn=50+5;
    struct Edge {int to,next;
int cap;
}edge0[maxn*maxn<<2],edge[maxn*maxn<<2];
int head[maxn<<1];
int maxedge0;
    inline void Addedge (int u,int v,int cap) {edge0[++maxedge0]= (Edge) {v,head[u],cap}; HEAD[U]=MAXEDGE0;
    Edge0[++maxedge0]= (Edge) {u,head[v],0};
HEAD[V]=MAXEDGE0;
int n,m;
BOOL Zero; inline BOOL Init () {if (!~read (n) | |!
    ~read (m)) return false; if (n==0| | N==1) &&m==0) {printf ("%d\n", N); Zero=true;return true;
    } memset (Head) (head,-1,sizeof);
    Maxedge0=-1;
    for (int i=1;i<=n;i++) Addedge (i,i+n,1);
        for (int i=1;i<=m;i++) {int a,b;
        Read (a), read (b);
        a++,b++;
        Addedge (A+n,b,inf);
    Addedge (B+n,a,inf);
return true;
} int d[maxn<<1],cur[maxn<<1];
BOOL vis[maxn<<1];
    inline bool BFs (int s,int T) {queue <int> que;
    memset (Vis) (vis,false,sizeof);
    Vis[s]=true;d[s]=1;que.push (S);
        while (!que.empty ()) {int U=que.front (); Que.pop ();
            for (int i=head[u];~i;i=edge[i].next) {if (!edge[i].cap) continue;//both cap>0 and non_visited!!!
            int v=edge[i].to;
            if (Vis[v]) continue;
  d[v]=d[u]+1;          if (v==t) return true;
        Que.push (v), vis[v]=true;
return false; int dfs (int u,int t,int minflow) {if u==t| |
    minflow==0) return minflow;
    int flow=0;
        for (int &i=cur[u];~i;i=edge[i].next) {int v=edge[i].to,f;
            if (d[v]==d[u]+1&& (F=dfs (V,t,min (MINFLOW,EDGE[I].CAP))) {edge[i].cap-=f;
            Edge[i^1].cap+=f;
            Flow+=f;
            Minflow-=f;
        if (!minflow) return flow;
} return flow;
    } inline int dinic (int s,int T) {int ret=0;
        while (BFS (s,t)) {memcpy (cur,head,sizeof);
    Ret+=dfs (S,t,inf);
return ret; } inline void edgecpy () {for (int k=0;k<=maxedge0;k++) edge[k]=edge0[k]; inline void expand (int x) {edge[(x&
lt;<1) -2].cap=inf;
    inline int work () {int ret=n;
            for (int i=1;i<=n;i++) for (int j=i+1;j<=n;j++) {edgecpy (); expand (i); expanD (j);
        int Tmp=dinic (i,j+n);//from inside Vertex if (ret>tmp) ret=tmp;
return ret;
    int main () {freopen ("tv.in", "R", stdin);
    Freopen ("Tv.out", "w", stdout);
        while (init ()) {if (Zero) {zero=false;continue;}
    printf ("%d\n", Work ());
return 0;
 }

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.