When submitting a solution in C++, please select either C++14 (GCC 6-32) or C++17 (GCC 7-32) as your compiler. ×

salt_n_ice's blog

By salt_n_ice, 3 years ago, In English

Link
I tried solving this using the ordered_set gnu pbds
I did dfs along with using swap and move methods for merging the sets of each node's children. The time complexity should be nlogn but why is it giving TLE on test 15?

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

»
3 years ago, # |
  Vote: I like it -16 Vote: I do not like it

Don't act like you really know how move works like, it's much more difficult than one can imagine. Read this.

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

    Okay move function doesn't work here but is there any way to make this approach work?

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

x.swap(ret). I also believe that ordered_set is not the intended solution anyway.

and move is useless here