Detect Cycle in Undirected Graph DFS
Given a simple undirected graph with n vertices numbered 0 through n - 1 and a list of undirected edges, decide whether the graph contains a cycle using depth-first search. Return true when at least one cycle exists and false otherwise.
Each entry in edges is an unordered pair [u, v] that connects u and v in both directions. The graph has no self-loops and no repeated unordered pairs, but it may be disconnected and a vertex may have no incident edges, so every unvisited vertex has to be considered as a possible component root.
Detect Cycle in Undirected Graph DFS
Given a simple undirected graph with `n` vertices numbered `0` through `n - 1` and a list of undirected edges, decide whether the graph contains a cycle using depth-first search. Return `true` when at least one cycle exists and `false` otherwise.