Algorithms
Cycle Detection:Directed, Undirected, and the Color/Parent Trick
Detect a directed cycle with 3-color DFS (gray means on the recursion stack) and an undirected cycle by skipping the parent — a visited flag alone is the diamond trap.
Read More