Any Cycle at All — Solution & Editorial
Union-find over the edges: an edge whose endpoints are already in the same set closes a cycle. DFS with parent tracking also works but multi-edges need care.
Complexity: O(M α(N))
Union-find over the edges: an edge whose endpoints are already in the same set closes a cycle. DFS with parent tracking also works but multi-edges need care.
Complexity: O(M α(N))