gauravahlawat81's blog

By gauravahlawat81, history, 5 years ago, In English

I am getting Memory limit exceeded on my test case #3 , but my algorithm is sure(I guess ?)

Can you please look at my code and tell me what could I possibly be doing wrong.

Thanks in advance.

Code Link: https://codeforces.com/contest/1167/submission/54276749

  • Vote: I like it
  • -3
  • Vote: I do not like it

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

You are adding $$$k^2$$$ edges for each group, where $$$k \leq n$$$, so your memory complexity (and time complexity) is $$$O(n^2)$$$. You only need to connect adjacent vertices i.e $$$k - 1$$$ edges for each group.