A directed graph has a cycle iff its depth-first search reveals a back edge

Proof:

(1)

If (u,v)(u, v) is a back edge, then there is a cycle consisting of this edge together with the path from vv to uu in the search tree.

(2)

If the graph has a cycle v0v1vkv0v_0 \rightarrow v_1 \rightarrow \cdots \rightarrow v_k \rightarrow v_0, look at the first node on this cycle to be discovered. Suppose it is viv_i, all the other vjv_j are reachable from it and will therefore be its descendants in the search tree. In particular, the edge vi1viv_{i-1} \rightarrow v_i leads from a node to its ancester and is thus by definition a back edge.