DFS fast in python

I was trying to solve FIRESC using http://www.codechef.com/viewsolution/3708062. Have used dfs implemented using stack in python and sys.stdin.readlines(). Yet, it is slow. Can someone suggest me if there is a faster way ? as here N=10^5, and it becomes slow for that.