Regarding this problem, https://csacademy.com/contest/archive/task/mountain-time/statement/, 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?).
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.