union-find implementation code