Checking if there is a single path that visits all nodes in a directed graph
The problem is how to deal with visited vertex.

If you keep following, the time complexity is not linear because of repeated visiting. Otherwise, your algorithm will fail in the following simple example:

1 --&gt; 2 -----------&gt; 3 --&gt; 4
        \         /
         --&gt; 5 --&gt;


The first search find 1-2-3-4, then it goes back to 2 and find 1-2-5-3. Now because 3 is visited, the search stops, and thus finally fails.

A hint (or answer) to solve the problem: performing a topological ordering firstly.