problem in detecting cycles in directed graph

algorithm
cycle
graph

#1

I have recently coded to detect cycles in directed graph [this][1] is link to my solution. My solution is working fine but I am getting TLE in one test case. Can any one please figure out what is bug in my code.
[1]: https://pastebin.com/wpVQ9qzB


#2

Can you share the problem link?


#3

The problem is:
return 0 if directed graph has a cycle and 1 otherwise.


#4

What are the constraints? Also, as @arpit728 pointed out, it’s hard to help you without the problem. We can’t tell if something you do in the code can be removed to decrease the runtime or if it’s essential to solving the problem.