In this problem I have applied normal DFS technique. But when I got TLE for the first time then I shift all i/o to scanf/printf thought it would be helpful. Then I googled for this problem and there used SCC(strongly connected components) technique. Now I want to know why 2-DFS technique is faster from 1-DFS technique here. Would someone explain this for me. my solution in c++ solution problem link problem on SPOJ