Connected components Adjacency List#10506

Connected components Adjacency List

1 second
128 megabytes
Medium

Find the number of connected components in a graph given by its adjacency list.

Input

The first line contains the number of vertices (1 \le n \le 10000). Each of the next lines describes the outgoing edges from the -th vertex. Each line begins with the number of outgoing edges, followed by the vertex numbers to which these edges go. All vertices are numbered from to .

Output

Print the number of connected components in the graph.

Examples

Example 1

Loading
Loading