Added UnionFind base class.