Tarjan's cycle detection algorithm is implemented for cycle prevention