Added Union-Find algorithm