#C3140. Minimum Unique Items Needed

    ID: 46535 Type: Default 1000ms 256MiB

Minimum Unique Items Needed

Minimum Unique Items Needed

You are given a list of tasks, where each task requires a collection of item IDs. Your goal is to determine the minimum number of unique items needed to complete all tasks. In other words, compute the size of the union of all item sets required by the tasks. Formally, if task i requires items represented by a set Ti, you need to calculate \(\left| \bigcup_{i=1}^{n} T_i \right|\).

The problem guarantees that the tasks may contain duplicate items both within the same task and across different tasks. Your program should efficiently count each distinct item only once.

inputFormat

The input is read from standard input (stdin) and has the following format:

 n
 k1 a1,1 a1,2 ... a1,k₁
 k2 a2,1 a2,2 ... a2,k₂
 ...
 kn an,1 an,2 ... an,kₙ

Here, the first line is an integer n, representing the number of tasks. For each of the next n lines, the first number k represents the number of items required for that task, followed by k integers denoting the item IDs.

outputFormat

Output a single integer to standard output (stdout) which is the number of unique items required to complete all tasks.

## sample
3
2 1 2
1 2
2 3 4
4