Skip to main content

Practice · 4 of 6

Contest 2 — Problem A: The Merge

CHALLENGE
Difficulty: advanced+25 XP

**Bài toán.** An empty graph has n isolated vertices. Edges arrive one by one (m edges total). After each edge arrives, print the number of connected components in the graph. **Constraints:** 1 ≤ n ≤ 200000; 1 ≤ m ≤ 250000; 1 ≤ u, v ≤ n (self loops possible). **Input:** line 1: n, m; then m lines: u, v. **Output:** m lines — the component count after each edge.

Back to lesson: Practice: Mock Contests 1 & 2