#P2835. 刻录光盘

刻录光盘

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 NN campers (2N200)(2 \le N \le 200), numbered 1N1 \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 NN indicating there are NN campers. The next NN lines respectively indicate which other campers each camper is willing to copy the materials to. Specifically, the (i+1)(i+1)-th line of the input indicates the IDs of the campers to whom the ii-th camper is willing to copy, ending with 00. If a camper is unwilling to copy to anyone, the corresponding line contains only 00. 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.

5
2 3 4 0
4 5 0
0
0
1 0
1

Hint

Translated by ChatGPT 5