#B3860. Package Dependency Installation Count

    ID: 11517 Type: Default 1000ms 256MiB

Package Dependency Installation Count

Package Dependency Installation Count

The pip install command is essential in Python for installing packages. However, many packages have dependencies and these dependencies must be installed prior to installing the package.

Assume there are packages numbered from $1 \sim N$. The $i$-th package has $K_i$ dependencies. Given that you want to install package 1, determine the total number of unique packages that will be installed (including package 1 and all its dependencies recursively).

You are given that the dependency graph has no cycles.

inputFormat

The input begins with a single integer $N$ representing the total number of packages. Following this are $N$ lines. The $i$-th line starts with an integer $K_i$ denoting the number of dependencies for package $i$, followed by $K_i$ space-separated integers each representing the package numbers that package $i$ depends on. It is guaranteed that each dependency is an integer between 1 and $N$ and the dependency graph does not contain cycles.

outputFormat

Output a single integer which is the number of unique packages that will be installed after installing package 1 and all its dependencies recursively.

sample

3
0
0
0
1

</p>