I am trying to do this question using Strongly Connected Components. Any idea on how to optimize code more for not getting TLE in last case ?
You can check your AC solution here: SAME SOLUTION AC
Check it out and you will get your mistake.
Oh, Thanks. Never thought this can make code give TLE. Will keep this in mind now. Thanks