Approach hintTry it first, then revealHide
A connected component forms a simple cycle exactly when every vertex in it has degree 2. Explore each component with DFS or BFS and check the degrees.
A connected component forms a simple cycle exactly when every vertex in it has degree 2. Explore each component with DFS or BFS and check the degrees.