A building logs n badge-scan records, numbered 0 through n-1. Each record lists the badge codes seen during one scan. Two records belong to the same real person if they share at least one badge code. This merging is transitive: if record A shares a code with B, and B shares a code with C, then A, B and C are all the same person.
Count how many distinct real people the n records represent.
Input format
- Line 1: an integer
n, the number of records. - Next
nlines: the record's badge codes. Each line begins with an integerk(the number of codes), followed bykinteger codes. A record may list zero codes.
Output format
A single integer: the number of distinct people.
Constraints
- 1 <= n <= 2000
- 0 <= k <= 20
- Each badge code is an integer between 1 and 1000000.