#P2835. Minimal Disc Propagation Problem

    ID: 16094 Type: Default 1000ms 256MiB

Minimal Disc Propagation Problem

Minimal Disc Propagation Problem

You are given N campers (2 ≤ N ≤ 200), each identified by a unique number from 1 to N. Each camper fills out a survey indicating the list of other campers whom they are willing to allow to copy materials from them. In other words, if camper A is willing to allow camper B to copy, then if A gets the disc, B may get a copy from A.

Furthermore, the copying is transitive. That is, if camper A allows camper B, and camper B allows camper C, then once A obtains the disc, both B and C will eventually get the materials.

Your task is to determine the minimum number of discs that need to be burned such that, through direct or transitive copying, every camper will eventually receive the summer camp materials.

Hint: Think in terms of directed graphs and strongly connected components. Each camper corresponds to a vertex and a survey entry A → B is a directed edge from A to B. Within a strongly connected component all campers can eventually share the disc if one of them obtains it. Thus, the answer is the number of source components in the condensation graph (i.e. components with no incoming edges from other components).

inputFormat

The input begins with a single integer N (the number of campers).

Then follow N lines. The i-th line first contains an integer k indicating the number of campers that camper i is willing to allow to copy from him. Then follow k integers, each representing the camper numbers that are allowed to copy from camper i.

outputFormat

Output a single integer — the minimum number of discs that need to be burned so that every camper can eventually receive the materials.

sample

3
1 2
1 3
0
1