Add union-find based code (currently unused)