Keep getting nzec in percapta after hours of trying!

I looked for out of bound list elements but could not find any and also tried multiple test cases. they are running fine can anyone tell me for which case this is getting nzec?
I really worked on it for hours.

https://www.codechef.com/viewsolution/34638641

Edit: Problem solved after setting recursion limit.

did you check out the editorial

Look whenever dealing with graph question using python, avoid recursive approaches, use iterative approach, reason being python has a small recursion stack compared to other languages (cpp and JAVA), if you want to use recursive approach always use recursion limit.

2 Likes

Follow @tusshar_2000’s advice. I added recursion limit to 1e9 and it gives AC.
Add this to the top of the code:

from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

Your code with recursion limit.

2 Likes

you are right. just set recursion limit and got ac. thanks!! I was looking for it for hours!!

2 Likes

I did. I dont really prefer asking anyone to debug my code. but i couldn’t get it right. I dont really work with recursion thats why i was having this problem.

yes i had no idea. i dont really solve problem with recursions. i avoid it if i can with bfs or dp.

1 Like