UVA-1660 Cable TV Network (min cut)

Source: Internet
Author: User

The main topic: to a N-point, M-edge of the graph, the minimum point cut set of the cardinality.

Problem Analysis: The base of the minimum point cut set of the graph can be changed to the minimum cut. Considering the graph of single source s single-sink T, if a minimum point set is required, so that the graph is no longer connected after the point set is removed (the number of connected components is increased), simply split each point into two (in and out points), and with a capacity of 1 arc, the other arc unchanged, on the new network to find the smallest cut will get the base of this minimum point set. But the subject is passive without sinks, you can specify a point as the source point, enumerate the other points as sinks, and obtain the n-1 of the point set base, the smallest is the answer. Be aware that each enumeration is re-built.

The code is as follows:

# include<iostream># include<cstdio># include<vector># include<queue># include<cstring ># include<algorithm>using namespace Std;const int inf=1<<30;const int maxn=105;struct Edge{int fr,to,c    AP,FW;        Edge (int fr,int to,int cap,int fw) {this->fr=fr;        this->to=to;        this->cap=cap;    this->fw=fw;    }};struct dinic{vector<edge>edges;    vector<int>g[maxn];    int D[MAXN],CUR[MAXN];    int vis[maxn],n,s,t;        void init (int n) {this->n=n;        Edges.clear ();    for (int i=0;i<n;++i) g[i].clear ();        } void Addedge (int u,int v,int cap) {Edges.push_back (Edge (u,v,cap,0));        Edges.push_back (Edge (v,u,0,0));        int m=edges.size ();        G[u].push_back (m-2);    G[v].push_back (m-1);        } bool BFs () {memset (vis,0,sizeof (VIS));        Vis[s]=1;        d[s]=0;        queue<int>q;        Q.push (s);        while (!q.empty ()) {    int U=q.front ();            Q.pop ();                for (int i=0;i<g[u].size (); ++i) {edge& e=edges[g[u][i]];                    if (E.cap>e.fw&&!vis[e.to]) {vis[e.to]=1;                    d[e.to]=d[u]+1;                Q.push (e.to);    }}} return vis[t]; } int dfs (int u,int a) {if (u==t| |        a==0) return A;        int flow=0,f;            for (int &i=cur[u];i<g[u].size (); ++i) {edge& e=edges[g[u][i]];                if (d[e.to]==d[u]+1&& (F=dfs (E.to,min (A,E.CAP-E.FW))) >0) {e.fw+=f;                Edges[g[u][i]^1].fw-=f;                Flow+=f;                A-=f;            if (a==0) break;    }} return flow;        } int Maxflow (int s,int t) {this->s=s,this->t=t;        int flow=0;            while (BFS ()) {memset (cur,0,sizeof (cur));        Flow+=dfs (S,inf);    } return flow; }};D INIC solver;string p;int n,m,mark[55];vector<edge>e;void addedge (int u,int v,int cap) {E.push_back (Edge (u,v,cap,0)) ;}    void Solve () {int len=p.size (), POS;    for (Pos=0;pos<len;++pos) if (p[pos]== ', ') break;    int a=0,b=0;    for (int i=1;i<pos;++i) a=a*10+p[i]-' 0 ';    for (int i=pos+1;i<len-1;++i) b=b*10+p[i]-' 0 ';    Addedge (A<<1|1,b<<1,inf); Addedge (B<<1|1,a<<1,inf);}        void Look () {for (int i=0;i<solver.edges.size (); ++i) {edge& e=solver.edges[i];    cout<<e.fr<< ' <<e.to<< ' <<e.cap<< ' <<e.fw<<endl;    }}int Main () {int A, B;        while (~SCANF ("%d%d", &n,&m)) {e.clear ();        for (int i=0;i<n;++i) Addedge (i<<1,i<<1|1,1);            while (m--) {cin>>p;        Solve ();        }//look ();        int ans=n,k=e.size ();            for (int i=1;i<n;++i) {solver.init (n*2); for (intJ=0;J&LT;K;++J) {Solver.addedge (E[J].FR,E[J].TO,E[J].CAP);            } int Flow=solver.maxflow (1,i<<1);        Ans=min (Ans,flow);    } printf ("%d\n", ans); } return 0;}

  

UVA-1660 Cable TV Network (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.