Practice · 1 of 5
Counting Components
CHALLENGE
Difficulty: intermediate+25 XP
**Description:** Count the connected components of an undirected graph.
**Input:** Line 1: n m (1 <= n <= 100000, 0 <= m <= 200000). Next m lines:
u v (1 <= u, v <= n).
**Output:** One integer — the number of components.
**Example:** 4 2 / 1 2 / 3 4 -> 2.
Press Submit to check your solution.
Back to lesson: Practice: Graph Theory Problem Set