Блог пользователя K.Outis

Автор K.Outis, история, 4 недели назад, По-английски

Ok Code Forces

I realize the error in the previous blog is huge and if I knew how to delete the blog I would have done so. Before I reach the poverty line in the Contribution area again.

But I really have a question this time!

I had written this code (296121982) for 113F but finally by converting the vector to a list I managed to solve this problem(296125493).

But I saw a friend who was able to solve the question with the same process(110436429). Can you guide me?

Thank you in advance.

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

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

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

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

Check your merge function (In the first attempt that you got Memory Limit Exceeded). instead of "-par[v] < -par[u]", use "par[u] > par[v]" since your intention is u>v (if im wrong then sorry again :))

»
4 недели назад, # |
Rev. 3   Проголосовать: нравится -15 Проголосовать: не нравится

shut up why you spam comment section Codeforces is getting TRASHED ALL BECAUSE OF YOU THE FUCK

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

Doing ans[v].clear() doesn't actually free up the memory used by the vector. Adding ans[v].shrink_to_fit() to free up the memory used by ans[v] makes your MLE submission TLE. This means your vector merging probably isn't optimal. Your friend's submission uses something called small-to-large merging, which you can find good explanations for online.

By the way, please ignore the troll comments above. They are just people who have nothing better to do with their time than belittle others.

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

    Um, I think the clear one still work? I can still Accepted this problem using the similar idea? Can you explain for me please?

    My attept: https://mirror.codeforces.com/contest/1131/submission/296130011

    • »
      »
      »
      4 недели назад, # ^ |
      Rev. 2   Проголосовать: нравится +6 Проголосовать: не нравится

      Here you are also doing small-to-large merging, so the memory complexity is $$$O(n \log n)$$$, which can pass. You merge $$$u$$$ to $$$v$$$ if $$$u$$$ is the representative of less nodes than $$$v$$$. The other submission does the opposite, so its memory complexity is $$$O(n^2)$$$.

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

    Yes. Thank you very much and I agree with you about the troll comments above.

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

I changed the line if (-par[v] < -par[u]) to if (par[v]<par[u]) and it worked

You probably meant to write if (-par[v] > -par[u])