Directed cycle detection

Check whether you can follow one-way streets and return to the place you started. If there is such a loop, the algorithm shows it.

Use three states: unvisited, currently exploring and finished. An edge into the active branch closes a cycle. Follow the parent chain to display it.

With adjacency lists, traversal takes O(V + E) time for V vertices and E edges.