Problem: Smallest String With Swaps Task: Given string and swap pairs, find the lexicographically smallest string achievable. Within each connected component of indices, you can arrange characters in any order.
Group indices by DSU, sort characters within each group, and place them back in sorted order. The insight: if you can swap index with , and with , then transitivity lets you swap with too. Connected components capture this transitive closure.