Independent Cycles — Solution & Editorial
Every edge that joins two already-connected vertices adds one independent cycle. Union-find counts exactly those: answer = M − (successful unions).
Complexity: O(M α(N))
Every edge that joins two already-connected vertices adds one independent cycle. Union-find counts exactly those: answer = M − (successful unions).
Complexity: O(M α(N))