Implement cycle detection in an undirected graph using DFS with parent tracking.
Constraints
Example
>>> has_cycle(4, [[0,1],[1,2],[2,0]]) True >>> has_cycle(4, [[0,1],[1,2],[2,3],[3,0]]) True >>> has_cycle(3, [[0,1],[1,2]]) False >>> has_cycle(5, [[0,1],[1,2],[2,3],[3,4]]) False
Recent Submissions
No submissions yet — hit Run Tests to try!
Hints