RECHEND help

hello everyone . i tried to solve RECHEND in python using DFS but it show runtime error. i would very much appreciate if anyone can tell me where i am doing wrong in my code.

my code: https://www.codechef.com/viewsolution/53084355