Problem:
You are given n elements and m merge queries. After processing every query, report how many disjoint sets remain.
Input format:
The first line contains two numbers n and m (1 ≤ n, m ≤ 100000). Each of the next m lines contains a pair a b (0 ≤ a, b < n) — the elements to merge.
Output format: Print a single number — the count of disjoint sets after all merges.
Solution:
The structure keeps a parent array where every element points at another element of its set. The representative of a set points at itself. Two optimisations keep the operations near-constant: path compression, which reattaches visited nodes straight to the root, and union by rank, which hangs the shallower tree under the deeper one.
The visualisation reads the parent array, so it must stay a flat list of integers.