Implementation of Union Find algorithms