← Back to topics
Topic

Can someone Help me with Task Ministri?

D
Dgleich
Can someone please help me?
h
hendrik
Hint: find cycle of a directed graph
D
Dgleich
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*
g
gates
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.
h
hendrik
hint: some nodes calculated more than once..
D
Dgleich
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...
h
hendrik
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...
D
Dgleich
*Code Updated
It works for 1,2,3,7 test case now...
any help?
It passed I didn't understood the task :)