Network
Time limit1sMemory limit128 MB
Given an undirected connected graph, count the articulation points whose removal disconnects some other pair of vertices. Input is line-oriented and ends with 0.
- Level
Medium6 of 10
- Topics
- Graph, DFS, Implementation, Brute force
- Solved
- No attempts yet
Problem
A telephone company is building a new telephone cable network. It connects several places numbered with integers from to ; no two places share a number. Every cable is bidirectional and directly joins exactly two places, and at each place the cables meet in a telephone exchange (one exchange per place).
From any place you can reach every other place through the cables, though not necessarily by a direct cable — the connection may pass through several exchanges. In other words, the network is connected.
Sometimes the power fails at a place and its exchange stops working. When that happens, not only is the failed place unreachable, but it may also become impossible for some other pair of places to reach each other. When the failure of a single place makes some other two places unable to reach each other, we call that place critical.
For each network, determine how many places are critical.
Input
The input consists of several blocks, each describing one network.
The first line of a block contains the number of places (). Each of the following (at most ) lines starts with the number of a place, followed by the numbers of some places to which it has a direct cable. Together these lines list every direct connection of the network: each cable appears in at least one line. All numbers on a line are separated by single spaces.
Each block ends with a line containing a single . The whole input ends with a block whose first line is ; that final block is not processed.
Output
For each block except the last, print a single line with the number of critical places in that network.
Hint
The neighbors of a place are listed on the same input line as that place, so line boundaries matter: read the input line by line. To make each line easy to delimit, there are no trailing spaces before the end of a line.