Mountain Time

Regarding this problem,, is there a built-in collection in java that allows o(1) for union like C++? I tried small-to-large merging for amortized log(n) merge but that seems to tle(or am I analyzing the time complexity incorrectly?).

Here is the submission:

Any help would be appreciated, thanks!

So is this about DSU? And what data structure allows for O(1) union in C++?

supposedly not?

No. In the problem, the merging of two collections could be needed when applying the merge operation for dsu. I was asking wether there is a way to do this efficiently in java.

Thank you.

I’m confused- you say that this isn’t about DSU, then you say that you need to merge two collections for DSU.