14212 - Bless of Stiff Waist Beast   

Description

"Bless of Stiff Waist Beast" is a computer virus that will cause the infected computer unable to operate properly. Please help us to calculate the number of infected computers.

The virus is spreading in a network of computers. The network is a tree with $N$ nodes, each node represents a computer. The nodes are numbered from $1$ to $N$ and node $1$ is the root of the tree. Each second, the virus will spread from each infected node to all its children. Initially, only node $1$ is infected. Please calculate the number of infected nodes after $K$ seconds.

  • This is a work of fiction. Any resemblance to actual events or persons is entirely coincidental.

Input

The first line contains two integers \(N\) and \(K\), indicating the number of nodes and the number of seconds passed. For the following \(N\) lines:

The \(i\)-th line starts with an integer \(M_i\), indicating the number of children of node \(i\). The following \(M_i\) integers \(c_{i,1}, c_{i,2}, \ldots, c_{i,M_i}\) indicate the children of node \(i\).

\(N \quad K\)
\(M_1 \quad c_{1,1} \quad c_{1,2} \quad \ldots \quad c_{1,M_1}\)
\(M_2 \quad c_{2,1} \quad c_{2,2} \quad \ldots \quad c_{2,M_2}\)
\(\enspace \vdots\)
\(M_N \quad c_{N,1} \quad c_{N,2} \quad \ldots \quad c_{N,M_N}\)

Constraints

\(1 \le N \le 5 \times 10^5\)
\(1 \le K \le 5 \times 10^5\)
\(1 \le M_i \le N-1\)
\(\sum_{i=1}^{N}{M_i} = N-1\)
\(1 \le c_{i,j} \le N\)

Output

Output one integer indicating the number of infected nodes after $K$ seconds.

You should print a newline('\n') character at the end of output.

Sample Input  Download

Sample Output  Download

Tags

Stiff Waist Beast



Discuss