Solution (source code)

= Solution

A <topological sort> of a <Directed acyclic graph> is a linear ordering of its vertices in which the tail of every directed edge precedes its head. Along a path $v_0\to v_1\to\cdots\to v_k$, this property successively gives
$$
v_0<v_1<\cdots<v_k
$$
in that ordering. Thus the vertices of every directed path occur in <topological order>. The acyclicity condition is necessary, since a directed cycle would force its first vertex to precede itself.