POJ 1966--cable TV Network "The point connectivity of undirected graphs is constructed with maximum flow model && Dinic"

Source: Internet
Author: User
Tags nets

Cable TV Network
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 4234 Accepted: 1989

Description

The interconnection of the relays in a cable TV network is bi-directional. The network is connected if there are at least one interconnection path between each pair of relays present in the network. Otherwise the network is disconnected. An empty network or a network with a single relay is considered connected. The safety factor F of a network with n relays is:
1. N, if the net remains connected regardless the number of relays removed from the net.
2. The minimal number of relays that disconnect the network when removed.

For example, consider the Nets from Figure 1, where the circles mark the relays and the solid lines correspond to Intercon Nection cables. The network (a) is connected regardless the number of relays that was removed and, according to rule (1), f=n=3. The network (b) is disconnected when 0 relays was removed, hence f=0 by rule (2). The network (c) is disconnected while the relays 1 and 2 or 1 and 3 are removed. The safety factor is 2.

Input

Write A program This reads several data sets from the standard input and computes the safety factor for the cable networks Encoded by the data sets. Each data set starts with a integers:0<=n<=50,the number of relays in the net, and M, the number of cables in the Net. Follow m data pairs (u,v), u < V, where u and V is relay identifiers (integers in the range 0..n-1). The pair (U,V) designates the cable that interconnects the relays U and v. The pairs may occur on any order. Except the (u,v) pairs, which do not contain white spaces, white spaces can occur freely in input. Input data terminate with an end of file and is correct.

Output

For each data set, the program prints on the standard output, from the beginning of a line, the safety factor of the Encod Ed Net.

Sample Input

0 01 03 3 (0,1) (0,2) 2 05 7 (0,1) (0,2) (1,3) (1,4) (2,3) (3,4)

Sample Output

01302

Hint

The first data set encodes a empty network, the second data set corresponds to a network with a single relay, and the FOL lowing three data sets encode the nets shown in Figure 1.

The definition of the point connectivity:
A figure g with N points, after removing any k-1 vertices (1<=k<=n), the resulting sub-graph is still connected, removing the k vertices is not connected, The G is a K-connected graph, and the
K is called the connectivity of graph G, which is recorded as K (g).
Workaround: Build the network flow model:
If G is an image without direction:
(1) each vertex in the original G graph becomes a two vertex v ' and V ' in the N net, and the vertex v ' to V ' has an arc capacity of 1;
(2) each edge of the E=UV in the N Net has two arc e ' = U ' V ', e ' = V ' u ' corresponds to, e ' and E ' are infinite;
(3) takes a ' as the source point, B ' is the sink point, and the maximum flow is obtained.

If G is a direction graph
(1), each vertex in the original G graph becomes the two vertices v ' and V ' in the N net, the vertex v ' to V ' has an arc with a capacity of 1;
(2) each arc in the original g graph is E = u v into a forward rail u ' u ' V ' V ' The capacity of the Arc U ' V ' on the middle rail is infinite;
(3) takes a ' as the source point and B ' is the maximum flow for the sink point.

Note that the source point of this enumeration is strongly connected to the sink point if the maximum flow for the meeting point of an enumeration is infinite. If all the enumeration results are infinite, then the entire graph G is strongly connected, and n-1 points need to be removed to disrupt their connectivity.

Edge Connectivity: Delete Only the edges to delete at least a few edges.
Build a network n
If G is an E=UV graph:
1. Each edge of the original G-chart becomes two-edged e ' =uv,e ' =vu, with a capacity of 1;
2. Enumerates a point as the source point, and then enumerates the sink points that are not adjacent to the source, seeking the maximum flow maxflow, Preserving the minimum maxflow is the edge connectivity of the graph.


If G is a direction graph:
1. The original G chart has a forward edge capacity of 1;
2. This step is the same as step 2 of the no-show diagram.


Note each time the source point is enumerated, the meeting point will find the smallest maxflow, and the flow of each edge edge[I]. Flow clear 0 , which stuck me all night, WA.

#include <cstdio> #include <cstring> #include <algorithm> #include <queue> #include <stack > #define INF 0x3f3f3f3f#define maxn 1000+10#define maxm 2000000+10using namespace std;struct Node {int u, V, cap, F Low, Next;};    Node Edge[maxm];int HEAD[MAXN], CUR[MAXN], Cnt;int DIST[MAXN], vis[maxn];int N, m;void init () {cnt = 0; Memset (Head,-1, sizeof (head));}    void Add (int u, int v, int w) {edge[cnt] = {u, V, W, 0, Head[u]};    Head[u] = cnt++;    EDGE[CNT] = {V, u, 0, 0, Head[v]}; HEAD[V] = cnt++;}    BOOL BFS (int st, int ed) {queue<int>q;    memset (Vis, 0, sizeof (VIS));    memset (Dist,-1, sizeof (Dist));    VIS[ST] = 1;    DIST[ST] = 0;    Q.push (ST);        while (!q.empty ()) {int u =q.front ();        Q.pop ();            for (int i = head[u]; i =-1; i = Edge[i].next) {node E = Edge[i];                if (!VIS[E.V] && e.cap > E.flow) {vis[e.v] = 1;                DIST[E.V] = Dist[u] + 1; if (e.v = = ed)return true;            Q.push (E.V); }}} return false;}    int DFS (int x, int ed, int a) {if (x = = Ed | | a = = 0) return A;    int flow = 0, F;        for (int &i = cur[x]; I! =-1; i = Edge[i].next) {node &e = Edge[i];            if (dist[e.v] = = Dist[x] + 1 && (f = DFS (e.v, ed, Min (A, e.cap-e.flow))) > 0) {e.flow + = f;            edge[i ^ 1].flow-= f;            A-= f;            Flow + + F;        if (a = = 0) break; }} return flow;}    int Maxflow (int st, int ed) {int flowsum = 0;        while (BFS (St, ed)) {memcpy (cur, head, sizeof (head));    Flowsum + = DFS (St, Ed, INF); } return flowsum;}        int main () {while (scanf ("%d%d", &n, &m)! = EOF) {int u, V, mins;        Init ();        for (int i = 0; i < n; ++i) Add (i, i + N, 1);            while (m--) {scanf ("(%d,%d)", &u, &v);            Add (U + N, v, INF);        Add (v + N, u, INF);        }mins = INF; for (int i = 0, i < n; ++i) for (int j = i + 1; j < n; ++j) {int sum = Maxflow (i +            N, j); for (int i = 0; i < cnt; ++i) {Edge[i].flow = 0;//the flow of each edge is cleared by 0} each time the maximum flow is found mins = min (mi        NS, sum);        } if (mins >= n) mins = n;    printf ("%d\n", mins); } return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

POJ 1966--cable TV Network "The point connectivity of undirected graphs is constructed with maximum flow model && Dinic"

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.