eolymp
bolt
Try our new interface for solving problems
Problems

Bounty Hunter II

Bounty Hunter II

Spike the bounty hunter is tracking another criminal through space. Luckily for him hyperspace travel has made the task of visiting several planets a lot easier. Each planet has a number of Astral Gates; each gate connects with a gate on another planet. These hyperspace connections are, for obvious safety reasons, one-way only with one gate being the entry point and the other gate being the exit point from hyperspace. Furthermore, the network of hyperspace connections must be loop-free to prevent the Astral Gates from exploding, a tragic lesson learned in the gate accident of 2022 that destroyed most of the moon. While looking at his star map Spike wonders how many friends he needs to conduct a search on every planet. Each planet should not be visited by more than one friend otherwise the criminal might get suspicious and flee before he can be captured. While each person can start at a planet of their choosing and travel along the hyperspace connections from planet to planet they are still bound by the limitations of hyperspace travel. \includegraphics{https://static.eolymp.com/content/9h/9h616aserd2l7c8lj1d74f1b64.gif} \InputFile Starts with an integer$n~(0 < n \le 1000)$ specifying the number of planets. The planets are numbered from $0$ to $n - 1$. The following $n$ lines specify the hyperspace connections. The $i$-th of those lines first contains the count of connections $k~(0 \le k \le n - 1)$ from planet $i$ followed by $k$ integers specifying the destination planets. \OutputFile Output the minimum number of persons needed to visit every planet.
Time limit 1 second
Memory limit 128 MiB
Input example #1
4
1 1
1 2
0
1 1
Output example #1
2
Input example #2
6
0
1 2
2 4 5
1 2
0
0
Output example #2
4
Source 2015 German Collegiate Programming Contest (GCPC), June 20, Problem B