ZOJ 2182 Cable TV Network (no-map cut-maximum flow)

Source: Internet
Author: User

Title Link: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2182

Test instructions: Give an undirected graph, ask at least how many vertices to delete after the diagram becomes disconnected?

Idea: The original image of each point of the split (I,i+n), the edge of <i,i+n,1>, the edge of the original (U,V), The Edge <u+n,v,INF>,<v+n,u,INF>. The maximum flow (i+n,j) is then run for each pair of vertices (i,j). The minimum value for all the maximum flows is the answer.

struct node{int v,cap,next;};    Node Edges[n*10];int head[n],e;int curedge[n],h[n],num[n],pre[n];int s,t;void Add (int u,int v,int cap) {edges[e].v=v;    Edges[e].cap=cap;    Edges[e].next=head[u]; head[u]=e++;}    void Add (int u,int v,int cap) {Add (U,V,CAP); Add (v,u,0);}    int maxflow (int s,int t,int n) {clr (h,0); CLR (num,0);    int i;    FOR0 (i,n+1) curedge[i]=head[i];    int u=s,min,k,x,ans=0;            while (h[u]<n) {if (u==t) {min=inf*100;                for (I=S;I!=T;I=EDGES[CUREDGE[I]].V) {x=curedge[i];                    if (edges[x].cap<min) {min=edges[x].cap;                K=i; }} ans+=min;            U=k;                for (I=S;I!=T;I=EDGES[CUREDGE[I]].V) {x=curedge[i];                Edges[x].cap-=min;            Edges[x^1].cap+=min; }} for (I=curedge[u];i!=-1;i=edges[i].next) {if (edges[i].cap>0&&h[u]==h[edges[i].v]+1) {break;            }} if (I!=-1) {curedge[u]=i;            Pre[edges[i].v]=u;        U=EDGES[I].V;            } else {if (--num[h[u]]==0) break;            Curedge[u]=head[u];            X=n;                for (I=head[u];i!=-1;i=edges[i].next) {k=edges[i].v;            if (edges[i].cap>0&&h[k]<x) x=h[k]; } h[u]=x+1;            num[x+1]++;        if (u!=s) u=pre[u]; }} return ans;    int N,m;int a[55][55];int visit[55];void DFS (int u) {visit[u]=1;    int i,v;    FOR1 (I,n) if (A[u][i]&&!visit[i]) {DFS (i);    }}int OK () {clr (visit,0);    DFS (1);    int i;    FOR1 (I,n) if (!visit[i]) return 0; return 1;}    int cal (int s,int t) {clr (head,-1); e=0;    int i,j;    FOR1 (i,n) Add (i,i+n,1);    FOR1 (I,n) for (j=1;j<=n;j++) if (A[i][j]) {ADD (i+n,j,inf); } returnMaxflow (s+n,t,n+n+2);}    int get () {int x=0;    Char C=getchar ();    while (!isdigit (c)) C=getchar ();        while (IsDigit (c)) {x=x*10+c-' 0 ';    C=getchar (); } return x;}            int main () {while (scanf ("%d%d", &n,&m)!=-1) {if (m==0) {if (n==0) puts ("0");            else if (n==1) puts ("1");            Else puts ("0");        Continue        } CLR (a,0);        int u,v,i;            FOR0 (i,m) {u=get (); V=get ();        A[u+1][v+1]=a[v+1][u+1]=1;            } if (!ok ()) {puts ("0");        Continue        } Int J;        int ans=inf;            FOR1 (I,n) for (j=1;j<=n;j++) if (i!=j) {int x=cal (I,J);        Ans=min (ANS,X); } if (ans==inf| |        ans==n-1) Ans=n;    PR (ANS); }}


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.