Connectivity Components - 2
Easy
Execution time limit is 1 second
Runtime memory usage limit is 64 megabytes
An undirected, unweighted graph is provided.
Your task is to determine the number of connected components in the graph and list them.
Input
The input consists of two integers, N and M (0 < N ≤ 100000, 0 ≤ M ≤ 100000). The next M lines each contain two integers, i and j (1 ≤ i, j ≤ N), indicating that there is an edge between vertices i and j.
Output
On the first line of the output, print the number of connected components. For each connected component, print two lines: the first line should contain the number of vertices in that component, and the second line should list the vertices in any order.
Examples
Input #1
Answer #1
Submissions 1K
Acceptance rate 29%