Electricity
Time Limit: 5000MS |
|
Memory Limit: 65536K |
Total Submissions: 4727 |
|
Accepted: 1561 |
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
Test instructions: There are p power plants, there is a C road between (this C road may not be able to connect all points, that is, there are outliers, so to calculate the figure is divided into several parts) let you ask to remove a point after the maximum number of BCC
#include <stdio.h> #include <string.h> #include <stack> #include <algorithm> #define MAX 21000# Define MAXM 2001000#define INF 0x7fffffusing namespace Std;int dfn[max],low[max];int dfsclock,ebccnt;int addbcc[MAX];// Note the number of BCC int head[max],ans,num;int iscut[max];//record is cut point struct node{int beg,end,next;} Edge[maxm];void init () {ans=0; memset (head,-1,sizeof (Head));} void Add (int u,int v) {edge[ans].beg=u; Edge[ans].end=v; Edge[ans].next=head[u]; head[u]=ans++;} void Tarjan (int u,int fa) {int i,v; Dfn[u]=low[u]=++dfsclock; int son=0;//records the number of child nodes for (i=head[u];i!=-1;i=edge[i].next) {v=edge[i].end; if (!dfn[v]) {son++; Tarjan (V,u); Low[u]=min (Low[u],low[v]); if (Dfn[u]<=low[v])//is a cut point, first regardless of whether it is the root node {addbcc[u]++;//This is a node of the cut point, the number of BCC plus 1 Iscut[u] = 1; }} else Low[u]=min (Dfn[v],low[u]); } if (Fa<0& &son<2)//Not root node {iscut[u]=0; addbcc[u]=0; } if (fa<0&&son>1)//is the root node {iscut[u]=1; addbcc[u]=son-1;//here, when it's the root node, the number of BCC is removed as the number of child nodes son//But because the top of our for loop in the BCC when all as a non-root node to seek such//its non-root node cut off After the BCC number is son+1, in order to last output when unified plus 1//Here we let addbcc[u]=son-1; }}void Find (int l,int r) {dfsclock=0; memset (low,0,sizeof (Low)); memset (dfn,0,sizeof (DFN)); memset (addbcc,0,sizeof (ADDBCC)); memset (iscut,0,sizeof (iscut)); num=0; for (int i=l;i<=r;i++) {if (!dfn[i]) {Tarjan (i,-1); Num++;//calculates that the original diagram is divided into several parts}}}int main () {int n,m,j,i,a,b; while (scanf ("%d%d", &n,&m), n|m) {if (m==0) {printf ("%d\n", n-1); Continue } init (); while (m--) {scanf ("%d%d", &a,&b); Add (A, b); Add (B,a); } find (0,n-1); int sum=-1; for (i=0;i<n;i++) Sum=max(Sum,addbcc[i]+num); printf ("%d\n", sum); } return 0;}
POJ 2117 Electricity "point double connectivity for the maximum number of BCC after deleting a point"