POJ 2117--electricity "point double unicom && ask to delete a point, the figure up to how many blocks connected"

Source: Internet
Author: User

Electricity
Time Limit: 5000MS Memory Limit: 65536K
Total Submissions: 4589 Accepted: 1512

Description

Blackouts and Dark Nights (also known as acm++) is a company that provides electricity. The company owns several power plants, each of the them supplying a small area that surrounds it. This organization brings a lot of problems-it often happens that there are not enough power on one area, while there is a Large surplus in the rest of the country.

Acm++ have therefore decided to connect the networks of some of the plants together. At least in the first stage, there are no need to connect all plants to a single network Up-to-create redundant connections on critical places-i.e. The network may contain cycles. Various plans for the connections were proposed, and the complicated phase of evaluation of them have begun.

One of the criteria that have to was taken into account is the reliability of the created network. To evaluate it, we assume this worst event that can happen are a malfunction in one of the joining points at the power Plants, which might cause the network to split into several parts. While each of these parts could still work, each of them would has to cope with the problems, so it's essential to minim Ize the number of parts into which the network would split due to removal of one of the joining points.

Your task is to write a software the would help evaluating this risk. Your program was given a description of the network, and it should determine the maximum number of non-connected parts from The network may consist after removal of one of the joining points (not counting the removed joining point itself).

Input

The input consists of several instances.

The first line of each instance contains, integers 1 <= P <= and C >= 0 separated by a single space. P is the number of power plants. The power plants has assigned integers between 0 and P-1. C is the number of connections. The following C lines of the instance describe the connections. Each of the lines contains and integers 0 <= p1, p2 < P separated by a single space, meaning this plants with number s P1 and P2 are connected. Each connection is described exactly once and there are at the most one connection between every.

The instances follow each and immediately, without any separator. The input is terminated by a line containing the zeros.

Output

The output consists of several lines. The i-th line of the output corresponds to the i-th input instance. Each line of the output consists of a single integer c. c is the maximum number of the connected parts of the Can is obtained by removing one of the joining points at power plants in the instance.

Sample Input

3 30 10 22 14 20 12 33 11 00 0

Sample Output

122


The maximum number of connected blocks in the figure after deleting a point

#include <cstdio> #include <cstring> #include <algorithm> #include <queue> #include <stack > #define MAXN 100000+10#define maxm 2000000+10using namespace std;int N, m;struct node {int u, V, next;}; Node Edge[maxm];int HEAD[MAXN], Cnt;int low[maxn];//from that point or its descendants through the back edge can reach the lowest int dfn[maxn];//The point's depth precedence number bool is_cut[maxn];/ /Mark this point is not cut point int add_bcc[maxn];//Remove that point increase the number of BCC int dfs_clock;//depth precedence counter int bccno[maxn];//belongs to which bccint bcc_cnt;//bcc counter int    Num;void init () {cnt = 0; Memset (Head,-1, sizeof (head));}    void Add (int u, int v) {edge[cnt] = {u, V, Head[u]};    Head[u] = cnt++;    EDGE[CNT] = {V, u, Head[v]}; HEAD[V] = cnt++;}        void Getmap () {while (m--) {int A, B;        scanf ("%d%d", &a, &b);        a++, b++;    Add (A, b);    }}void Tarjan (int u, int fa) {Low[u] = dfn[u] = ++dfs_clock;    int son = 0;        for (int i = head[u]; i =-1; i = edge[i].next) {int v = EDGE[I].V;            if (!dfn[v]) {son++;        Tarjan (V, u);    Low[u] = min (Low[u], low[v]);                if (u! = FA && Low[v] >= Dfn[u]) {//U is cut point, but not root node is_cut[u] = true;                The record U has several sub-nodes satisfying Low[v] >= Dfn[u] V,//If there is D, the cut point is removed and divided into D + 1 connected components, a new D add_bcc[u]++; Record the dots inside the bcc}} else if (v! = FA && Dfn[v] < Dfn[u]) {Low[u] = mi    N (Low[u], dfn[v]);//Back Edge Update}}//u is the root node, but it has only one child node, not the cut point if (U = = fa && son = = 1) is_cut[u] = 0; U is the root node, and its number of child nodes is >= 2, which is the cut point. After deleting the point,//u has several sub-nodes, it is divided into several bcc, new son-1 if (U = = fa && son > 1) add_bcc[u] = son-1;}    void Find () {memset (low, 0, sizeof (low));    memset (DFN, 0, sizeof (DFN));    memset (add_bcc, 0, sizeof (ADD_BCC));    memset (is_cut, 0, sizeof (is_cut));    memset (bccno, 0, sizeof (BCCNO));    Dfs_clock = bcc_cnt = 0;            num = 0;//records the original unicom block for (int i = 1; I <= n; ++i) if (!dfn[i]) {Tarjan (I, I);        num++; }}voID solve () {num = 0;    Find ();    int ans = 0;    printf ("***%d\n", num);        for (int i = 1; I <= n; ++i) {//printf ("---%d\n", add_bcc[i]);    ans = max (ans, add_bcc[i]); } printf ("%d\n", ans + num);}    int main () {while (scanf ("%d%d", &n, &m), n | | m) {if (M = = 0) {printf ("%d\n", n-1);        Continue;}        Init ();        Getmap ();    Solve (); } return 0;}


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

POJ 2117--electricity "point double unicom && ask to delete a point, the figure up to how many blocks connected"

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.