Simple logarithmic union-find datastructure.