Poj--1966--cable TV Network "undirected graph vertex Connectivity"

Source: Internet
Author: User

Links:http://poj.org/problem?id=1966

Test Instructions: an undirected graph, n points, M edges, to find the vertex connectivity of this graph.


idea: vertex connectivity, that is, the number of cut points in the minimum cut point set, the general method of finding the vertex connectivity of undirected graphs is to transform to the minimum cut of the network flow.

Build diagram:

(1) The original image of each point I split, split for I ' and I ', I ' to I ', an arc capacity of 1.

(2) for edges present in the original image (U, v), with two arcs (U ', V ') and (V ', U '), capacity INF.

(3) Find a source point I, this point cannot be adjacent to all other points are not able to find the minimum cut, with this point I ' as the source point, enumerate the meeting point J '.


After the diagram has been built, the maximum flow is n-1, and the least of the answers is the vertex connectivity of the graph, and I-I ' to I ' is the smallest cut-point set.


#include <cstring> #include <string> #include <fstream> #include <iostream> #include < iomanip> #include <cstdio> #include <cctype> #include <algorithm> #include <queue> #include <map> #include <set> #include <vector> #include <stack> #include <ctime> #include < cstdlib> #include <functional> #include <cmath>using namespace std; #define PI ACOs ( -1.0) #define MAXN 1010 #define EPS 1e-7#define INF 0x3f3f3f3f//0x7fffffff#define llinf 0x7fffffffffffffff#define seed 1313131#define MOD 10 00000007#define ll Long long#define ull unsigned ll#define lson l,m,rt<<1#define Rson m+1,r,rt<<1|1struct nod e{int u,v,w,next;} Edge[500000],edge2[500000];int Head[120],dist[120],cur[120],fa[120],num[120],vis[120];int N,m,k,cnt,nn,src,sink;    void Add_edge (int a,int b,int c) {edge2[cnt].u = A;    EDGE2[CNT].V = b;    EDGE2[CNT].W = C;    Edge2[cnt].next = Head[a]; Head[a] = cnt++;}    void BFs () {int x,i,j; Queue<int> q;    memset (dist,-1,sizeof (Dist));    memset (num,0,sizeof (num));    Q.push (sink);    Dist[sink] = 0;    Num[0] = 1;        while (!q.empty ()) {x = Q.front ();        Q.pop ();                for (I=head[x];i!=-1;i=edge[i].next) {if (dist[edge[i].v]<0) {DIST[EDGE[I].V] = dist[x] + 1;                num[dist[edge[i].v]]++;            Q.push (EDGE[I].V);    }}}}int augment () {int x=sink,a=inf;        while (X!=SRC) {a = min (A,EDGE[FA[X]].W);    x = edge[fa[x]].u;    } X=sink;        while (X!=SRC) {edge[fa[x]].w-= A;        EDGE[FA[X]^1].W + = A;    x = edge[fa[x]].u; } return A;    int Isap () {int i,x,ok,minm,flow=0;    BFS ();    for (i=0;i<=nn+5;i++) cur[i] = Head[i];    X=SRC;            while (DIST[SRC]&LT;NN) {if (X==sink) {flow + = augment ();        x = src;        } ok=0;               for (I=cur[x];i!=-1;i=edge[i].next) {if (EDGE[I].W && dist[x]==dist[edge[i].v]+1) { ok=1;                FA[EDGE[I].V] = i;                CUR[X] = i;                x = EDGE[I].V;            Break            }} if (!ok) {minm = nn; for (I=head[x];i!=-1;i=edge[i].next) if (edge[i].w && dist[edge[i].v]<minm) MINM=DIST[EDGE[I].V]            ;            if (--num[dist[x]]==0) break;            num[dist[x]=minm+1]++;            CUR[X]=HEAD[X];        if (X!=SRC) x=edge[fa[x]].u; }} return flow;}    int main () {int i,j;    int A, B;        while (scanf ("%d%d", &n,&m)!=eof) {memset (head,-1,sizeof (head));        CNT = 0;            for (i=0;i<n;i++) {Add_edge (i,i+n,1);        Add_edge (i+n,i,0);            } for (i=0;i<m;i++) {scanf ("(%d,%d)", &a,&b);            Add_edge (A+n,b,inf);            Add_edge (b,a+n,0);            Add_edge (B+n,a,inf);        Add_edge (a,b+n,0);        } int ans = INF;        nn = n * 2;            for (i=0;i<n;i++) {memset (vis,0,sizeof (VIS));            for (J=head[i];j!=-1;j=edge2[j].next) {VIS[EDGE2[J].V] = 1;            } int sum = 0;            for (j=0;j<n;j++) {if (vis[j]) sum++;                } if (Sum < n-1) {src = i + N;            Break            }} for (i=1;i<n;i++) {sink = i;            memcpy (edge,edge2,sizeof (node) *cnt);            int temp = ISAP ();        ans = min (ans, temp);        } if (ans = = INF) ans = n;    printf ("%d\n", ans); } return 0;}


Poj--1966--cable TV Network "undirected graph vertex Connectivity"

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.