Topological sort and cycle detection problem

Here’s a link to the problem:

Here’s my solution:

Where am I going wrong? I tried a lot of different things, but can’t figure it out.

~Thanks

So even though I could not figure out what was wrong with the original code, I figured out a fix.

The fix was to make 3 states instead of two for the vis array, namely not visited, visiting and visited.

(Instead of just 2, visited and not visited)