LunaticPriest's blog

By LunaticPriest, history, 5 years ago, In English

Hello, I'm solving a basic connected components . My code is this . I tried switching to bitsets and a map instead of vectors, and also wrote my dfs iteratively in case of stack overflow. What can be the problem? Thanks!

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

| Write comment?
»
5 years ago, # |
  Vote: I like it +3 Vote: I do not like it

You are using O(n^2) amounts of memory, which is too much.

When you try to access an element in a map in c++, if the element isn't there the default value of that element is inserted into the map, so your dfs blows up the memory.