This page is still under construction.

Parts of this page are still being built. What you see may change.

Network

Time limit1sMemory limit128 MB

Summary
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 11 to NN; 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 NN (N<100N < 100). Each of the following (at most NN) 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 00. The whole input ends with a block whose first line is N=0N = 0; 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.

Examples1

  1. Example 1

    Input
    5
    5 1 2 3 4
    0
    6
    2 1 3
    5 4 6 2
    0
    0
    
    Expected output
    1
    2