POJ 2117 Electricity "No direction graph to cut point" "to remove a point after the maximum number of BCC in the graph"

Source: Internet
Author: User

Electricity
Time Limit: 5000MS Memory Limit: 65536K
Total Submissions: 4597 Accepted: 1515

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

 A

2

Test instructions: gives you an n-dot and M-side graph without the number of BCC in the graph that you want to remove a point from.

Idea: Because the figure may exist in the isolated point, so we first asked out the original image into a few pieces, and then it is tarjan to get rid of the increase in the point of the BCC, the last to find the largest on the line.

Today Ah Foon told me that my undirected graph point connectivity template is a bit of a problem. Study one afternoon, finally KO.

non-point graph cutting points about templates: Point Me

AC Code:

#include <cstdio> #include <cstring> #include <queue> #include <stack> #include <algorithm > #define MAXN 10000+10#define maxm 200000+10using namespace Std;struct edge{int from, to, next;} Edge[maxm];int HEAD[MAXN], edgenum;//store pointer int add_bcc[maxn];//Remove this point increase the number of BCC int dfn[maxn];//The point's depth precedence int low[maxn];// Starting from this point or its descendants by the back edge can reach the lowest depth precedence of bool iscut[maxn];//whether the point is a cut point int dfs_clock;//timestamp int num;//Graph may exist independent points need to first calculate the number of blocks in the diagram void init () { Edgenum = 0;memset (Head,-1, sizeof (head));} void Addedge (int u, int v) {Edge E1 = {u, V, head[u]};edge[edgenum] = e1;head[u] = edgenum++; Edge E2 = {V, u, head[v]};//graph need reverse build edge edge[edgenum] = e2;head[v] = edgenum++;} void Getmap (int m) {int A, b;while (m--) {scanf ("%d%d", &a, &b), a++, B++;addedge (A, b);}} void Tarjan (int u, int fa)//u the parent node in the Dfs tree is fa{low[u] = dfn[u] = ++dfs_clock;int Child = 0;//Records the number of sub-nodes for (int i = head[u]; I! = -1; i = Edge[i].next) {Edge E = edge[i];int v = e.to;if (!dfn[v]) {Child++;tarjan (V, u); low[u] = min (Low[u], low[v]); if (Low[v] &G t;=Dfn[u]//Cut point first regardless of root node finally consider {Iscut[u] = true;add_bcc[u]++;//Add a bcc}}else if (Dfn[v] < Dfn[u] && v! = FA) Low[u] = m In (Low[u], dfn[v]);//reverse Edge update}//The root node is again judged if (FA < 0 && Child < 2) Iscut[u] = False, Add_bcc[u] = 0;//root node is not a cut point if ( FA < 0 && child > 1) iscut[u] = True, add_bcc[u] = child-1;//root node is the value of the cut point update add_bcc}void find_cut (int l, int r {memset (add_bcc, 0, sizeof (ADD_BCC)), memset (iscut, 0, sizeof (iscut)), memset (low, 0, sizeof), memset (DFN, 0, sizeof (DFN));d fs_clock = num = 0;for (int i = l; I <= R; i++) if (!dfn[i]) Tarjan (i,-1), num++;//calculate how many blocks are divided into}void solve (in    T L, int r) {int ans = 0;    for (int i = l; I <= R; i++) ans = max (ans, add_bcc[i]); printf ("%d\n", ans + num);} int main () {int N, m;while (scanf ("%d%d", &n, &m), n| |            m) {if (M = = 0) {printf ("%d\n", N-1);        Continue } init (); Getmap (M); Find_cut (1, n);//Find cut points and bccsolve (1, n);} return 0;}


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

POJ 2117 Electricity "No direction graph to cut point" "to remove a point after the maximum number of BCC in the graph"

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.