problem link: http://www.spoj.com/problems/PT07Z/
I have used both double BFS and double DFS for this but getting TLE for both approaches while these two approaches worked for C/C++ users. What can I do to optimize my code? What else is required to get it accepted? These are my two Solutions:
1) DFS approach: http://ideone.com/sIrQsD
2) BFS approach: http://ideone.com/7nHEcA