Блог пользователя codebuster_10

Автор codebuster_10, история, 17 месяцев назад, По-английски

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 :|

  • Проголосовать: нравится
  • +2
  • Проголосовать: не нравится

»
17 месяцев назад, # |
Rev. 2   Проголосовать: нравится +18 Проголосовать: не нравится

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.