Network
Time limit:1000ms Memory limit:10000k
Description
A telephone line company (TLC) is establishing a new telephone cable network. They is connecting several places numbered by integers from 1 to N. 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 is
Possible to reach through lines every other place, however it need is a direct connection, it can go through several E Xchanges. 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 there are a Direct line from this place. These at the very N lines completely describe the network, i.e., each direct connection of both places in the network is Contai Ned at the 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
5
5 1 2) 3 4
0
6
2 1 3
5 4 6 2
0
0
Sample Output
1
2
Hint
You need to determine the end of one line. In order to make it's easy to Determine,there is no extra blank before the end of each line.
Source
Central Europe 1996
Test Instructions : A graph is given to find out the number of joint points.
idea : The input format of the problem is very disgusting. To first enter an n, whether n is 0 to determine whether the program ends.
Next there are several lines, each beginning with a U, followed by several numbers indicating that they are connected to U. See the code.
In addition, the Tarjan algorithm template is used to find the cutting point.
The code is as follows:
/* * ID:J.SURE.1 * PROG: * lang:c++ * *#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <ctime>#include <cmath>#include <stack>#include <queue>#include <vector>#include <map>#include <set>#include <string>#include <climits>#include <iostream>#define PB push_back#define LL Long Longusing namespace STD;Const intINF =0x3f3f3f3f;Const DoubleEPS =1e-8;/****************************************/Const intN = -+5;BOOLMat[n][n], iscut[n];intDeep, dfn[n], N;voidInit () {memset(Mat,0,sizeof(MAT));memset(DFN,0,sizeof(DFN));memset(Iscut,0,sizeof(Iscut)); Deep =0;}intDfsintUintFA) {intLowu = Dfn[u] = ++deep;intson =0; for(intv =0; v < n; v++)if(Mat[u][v]) {if(!dfn[v]) {son++;intLOWV = DFS (v, u); Lowu = min (Lowu, LOWV);if(LOWV >= dfn[u]) iscut[u] =true; }Else if(Dfn[v] < Dfn[u] && v! = FA) {Lowu = min (Lowu, dfn[v]); } }if(FA = =-1&& son = =1) Iscut[u] =false;returnLowu;}intMain () {#ifdef j_sureFreopen ("000.in","R", stdin);//freopen ("999.out", "w", stdout);#endif while(scanf("%d", &n), N) {intU, v; Init (); while(scanf("%d", &u), u) {u--; while(GetChar ()! =' \ n ') {scanf("%d", &v); v--; MAT[U][V] = Mat[v][u] =true; }} DFS (0, -1);intAns =0; for(inti =0; I < n; i++) {if(Iscut[i]) ans++; }printf("%d\n", ans); }return 0;}
"Connect Graph | Cut point" POJ-1144 Network