Union-find improvements.
Flattening the tree.
Union-find improvements (path compression).