POJ 1966 ZOJ 2182 Cable TV Network

Source: Internet
Author: User

The solution of the vertex connectivity of undirected graphs, that is, how many points are removed at least to make undirected graphs disconnected.

"Honor" produced by our school "graph theory algorithm theory, realization and application" This book is written in error , please do not look, the correct is this:

For each vertex, divide it into two points, V and V ';

For each vertex, V to V ' is built with a capacity of 1;

For the non-forward edge (U,V), the <u ',v> and <v ',u> capacity are +∞;

It then enumerates each pair of points (x, y) that are directly connected to no edge, X ' is the source point, Y is the sink point, and the maximum flow is run. The minimum value of the maximum stream is the answer.

#include <cstdio>#include<cstring>#include<string>#include<cmath>#include<vector>#include<queue>#include<algorithm>using namespacestd;Const intmaxn= ++Ten;Const intinf=99999999;structedge{int  from, To,cap,flow;}; Vector<Edge>Edges;vector<int>G[MAXN];BOOLVIS[MAXN];intD[MAXN];intCUR[MAXN];intn,m,s,t;intN,m;//n nodes, M-EdgeintLT[MAXN][MAXN];//determine if two points are connected directly//finding a hierarchical networkBOOLBFS () {memset (Vis,0,sizeof(VIS)); Queue<int>Q;    Q.push (s); D[s]=0; Vis[s]=1;  while(!Q.empty ()) {        intx=Q.front ();        Q.pop ();  for(intI=0; I<g[x].size (); i++) {Edge& e=Edges[g[x][i]]; if(!vis[e.to]&&e.cap>e.flow) {vis[e.to]=1; D[e.to]=d[x]+1;            Q.push (e.to); }        }    }    returnvis[t];}//Add EdgevoidAddedge (int  from,intTo,intcap)    {Edge R; R. from= from; R.to=to ; R.cap=cap; R.flow=0;    Edges.push_back (R);    Edge D; D. from=to ; D.to= from; D.cap=0; D.flow=0;    Edges.push_back (d); M=edges.size (); g[ from].push_back (M-2); G[to].push_back (M-1);}//Each phase comes with a DFS augmentationintDFS (intXinta) {    if(x==t| | a==0)returnA; intflow=0, F;  for(intI=CUR[X]; I<g[x].size (); i++) {Edge& e=Edges[g[x][i]]; if(d[x]+1==d[e.to]&& (F=dfs (E.to,min (a,e.cap-e.flow)) >0) {E.flow+=F; Edges[g[x][i]^1].flow-=F; Flow+=F; A-=F; if(a==0) Break; }    }    returnflow;}//multiple stages, several times to establish a hierarchical network. intMaxflow (intSsintTT) {    intflow=0;  while(BFS ()) {memset (cur,0,sizeof(cur)); Flow+=DFS (Ss,inf); }    returnflow;}intMain () { while(~SCANF ("%d%d",&n,&M)) {edges.clear ();  for(intI=0; i<maxn; i++) g[i].clear (); memset (LT,0,sizeof(LT));  for(intI=0; i<maxn; i++) lt[i][i]=1;  for(intI=0; i<n; i++) Addedge (i,i+n,1);  while(m--)        {            intu,v; scanf ("(%d,%d)",&u,&v); Addedge (U+n,v,inf);             Addedge (V+n,u,inf); lt[u][v]=lt[v][u]=1;//U and v are directly connected        }        intans=INF;  for(intIi=n; ii<2*n; ii++)        {             for(intI=0; i<n; i++) {s=ii,t=i; if(!lt[s-n][t])//consider whether the two points in the original image are directly connected                {                     for(intj=0; J<edges.size (); J + +) Edges[j].flow=0; Ans=min (Maxflow (s,t), ans); }            }        }        if(Ans>=inf) ans=N; printf ("%d\n", ans); }    return 0;}

POJ 1966 ZOJ 2182 Cable TV Network

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.