Can someone please help me?
Can someone Help me with Task Ministri?
Hint: find cycle of a directed graph
Here is my code can someone see why doesn't it work for testcases, it works only for the first one and I get TLE on some of them...?
removed*
removed*
think of one big cycle, then you'll visit whole cycle N times, if N is number of nodes in the cycle.
so complexity is O( n^2 ) which is too much.
so complexity is O( n^2 ) which is too much.
hint: some nodes calculated more than once..
I was thinking of re calculating but if I return that solution it will be the best solution starting from that one with some of them that I used in current solution...
Here is what I mean:
example : 1-> 2->3->1
after you found a cycle (1,2,3) mark the set...
but in your program you test 1,2,3 which make your program slower...
example : 1-> 2->3->1
after you found a cycle (1,2,3) mark the set...
but in your program you test 1,2,3 which make your program slower...
*Code Updated
It works for 1,2,3,7 test case now...
any help?
It passed I didn't understood the task :)
It works for 1,2,3,7 test case now...
any help?
It passed I didn't understood the task :)