Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

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

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

I am getting MLE for this code https://codeforces.net/contest/1774/submission/186717963 Please Anyone Can help?

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

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

Hey man, i solved ur memory problem with the following submission: https://codeforces.net/contest/1774/submission/186734301

However, I got a time limit exceeded on the next test (22). Do u think u could give me a time complexity analysis for ur code to see what is the problem?

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

    for my code the time complexity was O(n); where n is number of nodes

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

      can u double check this please because my changes have not affected anything in your code but it is giving time limit exceeded on testcase 22.

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

        The one thing more i have done is predefining the size of curr vector so to avoid mutliple times reallocation of size of the vector

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

Now i gets accepted by passing the visited vector by reference... !!

Thanks @TheOpChicken123 for pointing out.

»
21 месяц назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

Pass the reference for visted and curr vectors and make the necessary changes in update() and DFS() functions.

This is ACCEPTED submission of your code.

1st Change
2nd Change

Hope you got it right :)