POJ 1966 Cable TV Network (vertex connectivity for undirected graphs)

Source: Internet
Author: User

POJ 1966 Cable TV Network

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


Test Instructions: in a cable TV network, the repeater connection is bidirectional. If there is at least one route between any two repeaters in the network, the repeater network is called connected, or the repeater network is not connected. An empty network, and a network with only one repeater, are considered to be connected. The safety factor F of a network with n repeaters is defined as:
(1) F is n, the remaining network is still connected, regardless of the number of repeaters removed;
(2) F is to delete the least number of vertices, so that the remaining network is not connected.

Now given a cable TV network, ask how much f is.


idea: a connected graph, the minimum number of points to delete, can make the graph is no longer connected, this is the problem of vertex connectivity of undirected graphs.

The point connectivity of undirected graphs:
1. Split each point u ', u '. Vertex u ' to u ' with an arc with a capacity of 1.
2. Split each edge (U, v) in the diagram into <u ', V ' > and <v ', U ' > Two edges, and the capacity of each edge is INF.
3. Select a source point a ', enumerate the meeting point B '. The minimum value of the maximum flow is the point connectivity.
4. The vertex v corresponding to the arc (V ', V ') with Flow 1 constitutes a set of cut points.


Code:

/*id: [email protected]prog:lang:c++*/#include <map> #include <set> #include <queue> #include <stack> #include <cmath> #include <cstdio> #include <vector> #include <string> #include <fstream> #include <cstring> #include <ctype.h> #include <iostream> #include <algorithm> Using namespace std, #define INF (1<<30) #define PI ACOs ( -1.0) #define MEM (A, B) memset (A, B, sizeof (a)) #define REP (I, A, n) for (int i = A; i < n; i++) #define PER (l, a, n) for (int i = n-1; I >= A; i--) #define EPS 1e-6#define debug Puts ("===============") #define PB Push_back#define MP Make_pair#define All (x) (x). Begin (), (x). End () #define FI first# Define SE second#define SZ (x) ((int) (x). Size ()) #define Posin (x, y) (0 <=) && (x) < n && 0 <= (y ) && (Y) < m) typedef long Long ll;typedef unsigned long long ull;const int MAXN = 1000;const int maxm = 100000;    int edge[maxm][2];struct node {int v; vertex int cap;   capacity int flow; Current flow in this arc int nxt;}    E[MAXM * 2];int G[MAXN], Cnt;int St, Ed, N, m;void Add (int u, int v, int c) {e[++cnt].v = v;    E[cnt].cap = C;    E[cnt].flow = 0;    E[CNT].NXT = G[u];    G[u] = cnt;    E[++CNT].V = u;    E[cnt].cap = 0;    E[cnt].flow = 0;    E[CNT].NXT = G[v]; G[V] = cnt;}    void init (int N) {cnt = 1;    st = N;    for (int i = 0; i < n; i++) g[i] = 0;    int u, v;    for (int i = 0; i < N; i++) Add (i, i + N, 1);        for (int i = 0; i < m; i++) {int u = edge[i][0], v = edge[i][1];        Add (v + N, u, INF);    Add (U + N, V, INF);    }}int DIST[MAXN], NUMBS[MAXN], q[maxn];void rev_bfs () {int font = 0, rear = 1;        for (int i = 0; I <= N; i++) {//n is the total number of points dist[i] = MAXN;    Numbs[i] = 0;    } Q[font] = ed;    Dist[ed] = 0;    Numbs[0] = 1;        while (font! = rear) {int u = q[font++]; for (int i = g[u]; i; i = e[i].nxt) {if (e[i ^ 1].cap = = 0 | | dist[e[i].v] &Lt            MAXN) continue;            DIST[E[I].V] = Dist[u] + 1;            ++NUMBS[DIST[E[I].V]];        q[rear++] = E[I].V;    }}}int Maxflow () {REV_BFS ();    int u, totalflow = 0;    int CURG[MAXN], REVPATH[MAXN];    for (int i = 0; I <= N; ++i) curg[i] = G[i];    u = st;            while (Dist[st] < n) {if (U = = ed) {//Find an augmenting path int augflow = INF;            for (int i = st; I! = ed; i = e[curg[i]].v) augflow = min (Augflow, e[curg[i]].cap);                for (int i = st; I! = ed; i = e[curg[i]].v) {e[curg[i]].cap-= Augflow;                E[curg[i] ^ 1].cap + = Augflow;                E[curg[i]].flow + = Augflow;            E[curg[i] ^ 1].flow-= Augflow;            } Totalflow + = Augflow;        u = st;        } int i;        for (i = curg[u]; I, i = e[i].nxt) if (E[i].cap > 0 && dist[u] = = DIST[E[I].V] + 1) break; if (i) {//Find an admissible arc, then AdvancE Curg[u] = i;            REVPATH[E[I].V] = i ^ 1;        u = e[i].v;    } else {//no admissible arc, then relabel this vertex if (0 = = (--numbs[dist[u]])) break;            GAP Cut, important!            Curg[u] = G[u];            int mindist = n;            for (int j = g[u]; j; j = e[j].nxt) if (E[j].cap > 0) mindist = min (mindist, dist[e[j].v]);            Dist[u] = mindist + 1;            ++numbs[dist[u]];    if (U! = st) U = E[REVPATH[U]].V; Backtrack}} return totalflow;}    int main () {int N;        while (~SCANF ("%d%d", &n, &m)) {n = 2 * n + 4;        for (int i = 0; i < m; i++) scanf ("(%d,%d)", Edge[i], Edge[i] + 1);        int ans = INF;            for (int i = 1; i < N; i++) {ed = i;            Init (N);        ans = min (ans, maxflow ());        } if (ans = = INF) ans = N;    printf ("%d\n", ans); } return 0;}


POJ 1966 Cable TV Network (vertex connectivity for undirected graphs)

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.