codebuster_10's blog

By codebuster_10, history, 18 months ago, In English

I submitted following solutions to This problem :

  • 207930808 : my submission using dfs gives runtime error on test 17 when ran on pypy — 64.
  • 207931701 : same submission using dfs gives runtime error on test 13 when ran on python — 3.
  • 207933061 : this submission using queue (without recursion) passes.
  • 207933318 : if I set recursion limit then this gives MLE on test 1 when ran on pypy — 64.
  • 207933634 : but same code as above gives runtime error on test 16 when ran on python — 3.

Can someone please help why this is happening and how to avoid these runtime errors while writing recursive functions in python ? Or maybe their is something wrong with my logic itself and functions are correct :|

  • Vote: I like it
  • +2
  • Vote: I do not like it

»
18 months ago, # |
Rev. 2   Vote: I like it +18 Vote: I do not like it

Runtime error is due to max stack depth exceeded. You can try to sys.setrecursionlimit() and try to find a suitable value that does not give MLE (most likely not possible).

However I will suggest you to always write iterative dfs in python. Python recursive stack is huge and slow.