I've been trying to solve this [question](http://www.spoj.com/problems/ADACYCLE/), but I keep on getting a TLE. At first I had an O(V*(E+V)) approach ([link](http://p.ip.fi/QP1E)). Then I optimized my code so that I store the results of other nodes while calculating the answer of some node. ([link](http://p.ip.fi/cZlT)). I'm still getting an TLE.↵
↵
Can anyone please suggest another optimization/approach for this question so that I can get an AC?
↵
Can anyone please suggest another optimization/approach for this question so that I can get an AC?