Detect Cycle in Undirected Graph — Interactive Visualizer

Use DFS to check for cycles. We find a cycle when we explore a node that is already visited and is not the direct parent of the current node.