Connected components Adjacency List#10506

Connected components Adjacency List

1 Sekunde
128 Megabyte
Mittel

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

Eingabe

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 .

Ausgabe

Print the number of connected components in the graph.

Beispiele

Beispiel 1

Loading
Loading