https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem= 251
A telephone line company (TLC) is establishing a new telephone cable network. They is connecting several places numbered by integers from 1 toN. No. Places has the same number. The lines is bidirectional and always connect together both places and in each place the lines end in a telephone exchange . There is one telephone exchange in each place. From each place it's possible to reach through lines every other place, however it need isn't be a direct connection, it CA n go through several exchanges. From time to time the power supply fails in a place and then the exchange does not operate. The officials from TLC realized so in such a case it can happen that besides the fact that the place with the failure is Unreachable, this can also cause the some other places cannot connect to each of the other. In such a case we'll say the place (where the failure occured) is critical. Now the officials is trying to write a program for finding the number of all such critical places. Help them.
Input
The input file consists of several blocks of lines. Each block describes one network. The first line of each block there is the number of places N < 100. Each of the next at most N lines contains the number of a place followed by the numbers of some places to which t Here are a direct line from the this place. These at the veryN lines completely describe the network, i.e., each direct connection of both places in the network I s contained at least in one row. All numbers on one line is separated by one space. Each block ends with a line containing just 0. The last block had only one line with N = 0.
Output
The output contains for each block except the last in the input file one line containing the number of critical places.
Sample Input
55 1 2 3 4062 1 35 4 6 200
Sample Output
12
The main idea: to give you an no-map, the number of cut points. Input data first row one n means there are n points followed by a number of lines, until read into a 0, the entire map read into the end, and then read into a 0, the end of the file data. Each row has the first number a, which means that the next number is connected to a. Cut point: In an undirected connected graph, if a point is deleted, the graph becomes disconnected, and the point is called a cut point. Here the cutting point and the bridge are the concept of the non-direction diagram, we do not confuse here. To cut points a vertex u is a cut point, when and only if satisfies (1) or (2) (1) U is a root, and U has more than one subtree. That is, the code in Rootson >1 (2) U is not a root, and satisfies the presence (U,V) as a branch edge (or parent-child edge, that is, U is v in the search tree of the father), making DFN (U) <=low (v). (That is, V has no way to bypass the U point to reach a point smaller than u DFN) that is the code if (Dfn[v] <= low[i]) cut[i] = true; Note: The tree here refers to the search tree under DFS. Cut point Tarjan Low and dfndfn[u] definition is similar to the previous, but low[u] defined as U or u in a subtree can be traced through non-parent-child edge of the first node of the DFS start time in the Tarjan algorithm to cut point we want to add an array f[u], to determine whether the two are parent-child side
#include <stdio.h>#include<string.h>#include<math.h>#include<stdlib.h>#include<vector>#defineN 110#defineMin (A, B) (a < b? a:b)using namespaceStd;vector<vector<int> >G;intLow[n], dfn[n], f[n];intN, time, num;BOOLCut[n];voidInit () {g.clear (); G.resize (n+1); memset (Low,0,sizeof(low));//The first time to arrive at that pointmemset (DFN,0,sizeof(DFN));//The earliest time that the point can reach the previous pointMemset (F,0,sizeof(f));//Save a point's parent nodememset (Cut,false,sizeof(Cut));//determine if this is a cut pointTime = num =0;}voidTarjan (intUintFA) { intLen, V, I; Low[u]= Dfn[u] = + +Time ; F[u]=FA; Len=g[u].size (); for(i =0; i < Len; i++) {v=G[u][i]; if(!Dfn[v]) {Tarjan (V, u); Low[u]=min (Low[u], low[v]); } Else if(FA! =v) low[u]=min (Low[u], dfn[v]); }}voidSolve () {intRootson =0, I, V; Tarjan (1,0); for(i =2; i<= N; i++) {v=F[i]; if(v = =1)//The parent node of I is the root noderootson++;//Sub-tree Else if(Dfn[v] <=Low[i]) CUT[V]=true; } for(i =2; I <= N; i++) if(cut[i]) num++; if(Rootson >1) Num++;}intMain () {intA, B; Charch; while(SCANF ("%d", &N), N) {Init (); while(SCANF ("%d", &a), a) { while(SCANF ("%d%c", &b, &ch)) {G[a].push_back (b); G[b].push_back (a); if(ch = ='\ n') Break; }} Solve (); printf ("%d\n", num); } return 0;}
UVA 315 Network (connecting graph for cutting points)