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

Автор 3905, история, 8 лет назад, По-английски

Hello my submission for the problem http://mirror.codeforces.com/problemset/problem/691/D gets MLE while I have seen similar solutions getting passed using lesser memory.Can someone explain what is the reason behind it. My submission http://mirror.codeforces.com/contest/691/submission/19745411 & other similar solutions are http://mirror.codeforces.com/contest/691/submission/19081882 & http://mirror.codeforces.com/contest/691/submission/19274092 & http://mirror.codeforces.com/contest/691/submission/19107997. Thanks!

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

»
8 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by 3905 (previous revision, new revision, compare).

»
8 лет назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

All other submissions use some kind of structure — arrayList or queue and you use recurrence, which may cause stack overflow and that's probably what happens, if you change your code to use structures it should be okay.

  • »
    »
    8 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    I am also using ArrayList structure.I don't understand what you mean by recurrence.Is that it in dfs?Every submission in dfs have used recurrence structure.

    • »
      »
      »
      8 лет назад, # ^ |
        Проголосовать: нравится +1 Проголосовать: не нравится

      Two of those submissions use bfs not dfs so they have no problem with recurrence stack, I resubmitted the one with dfs and it barely passes the test your code is failing on, I personally would still rewrite that method, because recurrence DFS may cause problems like that, even if it's not the case here. The other thing I see you're initializing vertex and values lists n times, that may also cause some memory problems.