union-find algo added