A directed graph has a cycle iff its depth-first search reveals a back edge
Proof:
(1)
If is a back edge, then there is a cycle consisting of this edge together with the path from to in the search tree.
(2)
If the graph has a cycle , look at the first node on this cycle to be discovered. Suppose it is , all the other are reachable from it and will therefore be its descendants in the search tree. In particular, the edge leads from a node to its ancester and is thus by definition a back edge.