P2835 Burning CDs

Background

As the JSOI 2005 summer camp was about to end, many campers suggested burning all the materials from the entire camp onto a single CD for everyone, so they could continue studying after going home. The organizing committee thought this was a good idea! However, they did not have enough blank CDs at the moment to ensure that everyone could get one, and there was no time to buy more. What should they do?

Description

The organizing committee handed this problem to LHC. After analyzing the campers’ locations, LHC found that some campers are from the same city. In fact, they only need one disc, because once one person gets the disc, others can bring a USB drive and copy the materials. However, after investigation, LHC discovered that, for various reasons, some campers are not very cooperative: they are willing to let certain people copy materials from them, but unwilling to let others do so. This goes against the team spirit promoted by JSOI. Now suppose there are $N$ campers $(2 \le N \le 200)$, numbered $1 \sim N$. LHC gave everyone a survey form to fill in the people they are willing to let copy materials from them. Of course, if A is willing to copy to B, and B is willing to copy to C, then once A obtains the materials, both B and C will obtain them. Please write a program that, based on the returned survey forms, helps LHC compute the minimum number of CDs the organizing committee must burn to ensure that all campers can get the summer camp materials after going home.

Input Format

First is a number $N$ indicating there are $N$ campers. The next $N$ lines respectively indicate which other campers each camper is willing to copy the materials to. Specifically, the $(i+1)$-th line of the input indicates the IDs of the campers to whom the $i$-th camper is willing to copy, ending with $0$. If a camper is unwilling to copy to anyone, the corresponding line contains only $0$. Numbers on a line are separated by a single space.

Output Format

A single positive integer, indicating the minimum number of CDs that must be burned.

Explanation/Hint

Translated by ChatGPT 5