finished 2 versions of detectCycleUndirected one of which uses the Union-Find algorithm