#t522. 刻录光盘
刻录光盘
Burning CDs
Special for beginners, ^_^
Problem Description
Towards the end of the FJOI2010 summer camp, many campers suggested burning all the camp's materials onto a CD for everyone, so that they could keep learning after going home. The organizing committee liked the idea! But for a moment there were not enough blank CDs to guarantee that everyone would get one burned with the materials — what to do?!
DYJ analyzed where all the campers live and found that some come from the same city; in fact they only need one CD, because once one person has it, the others can copy the materials using a USB drive or similar.
Some people are willing to let certain others copy materials from them, while they may not be willing to let some other people copy — this goes completely against the teamwork spirit FJOI promotes!!!
Suppose there are campers in total (), numbered . DYJ gave everyone a survey asking each camper to state from which people they are willing to copy materials. Of course, if A is willing to copy materials to B, and B is willing to copy to C, then once A obtains the materials, both B and C will obtain them.
Now write a program that, based on the returned surveys, helps DYJ compute the minimum number of CDs the committee must burn so that every camper can obtain the camp materials after going home.
Input Format
First comes a number ; the next lines state which other campers each camper is willing to copy his obtained materials to. That is, line lists the numbers of the campers to whom camper is willing to copy materials, ending with a . If a camper is willing to copy to no one, the corresponding line contains only a single . The numbers on one line are separated by a space.
Output Format
A positive integer: the minimum number of CDs to burn.
Sample Input 1
5
2 4 3 0
4 5 0
0
0
1 0
Sample Output 1
1
Constraints
1s, 1024KiB for each test case.