ARYANK3024's blog

By ARYANK3024, history, 2 years ago, In English

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

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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?

  • »
    »
    2 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

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

    • »
      »
      »
      2 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      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.

      • »
        »
        »
        »
        2 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        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

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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

Thanks @TheOpChicken123 for pointing out.

»
2 years ago, # |
  Vote: I like it +3 Vote: I do not like it

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