Island Mergers
Challenge on lesson: Contest 2-B: Island Mergers
CHALLENGE
Difficulty: advanced+25 XP
**Problem.** Line 1: n k. Then k lines: u v — after each line, the two islands merge if not already connected. After EVERY line print the current number of connected island groups. **Constraints:** 1 <= n, k <= 200000; 1 <= u, v <= n. **R versus W.** The graded wrong solution rescans all roots after each union — correct output, O(n) per operation, hopeless at full load. Target: full solve within 40 minutes.
Press Submit to check your solution.
Back to lesson: Contest 2-B: Island Mergers