Problem link In this all first and third operation is the same as DSU. But in the second operation move(a, b) we have to move element 'a' to group containing b.
My approach: Instead of changing parent structure, I am using a different a vector parent2 for updating parent of element in move operation.
Code. Code . Correct code
I am getting the wrong answer.
The problem link doesn't open
This can be done by maintaining which number belongs to which dis-joint set. You can use sets to maintain this which could give you O(1) operation for second operation. Whenever you would try to combine 2 disjoint sets, you would merge the smaller one into the bigger one. This would ensure you don't have O(n^2) operations.
Can you elaborate on the "You can use sets to maintain this which could give you O(1) operation for second operation" part a little more ?
I am not good with markup that is used in codeforces (or anywhere else). So I am going the attach a piece of code in this comment which is a O(nlogn) implementation of DSU. This implementation uses LinkedList (can use vector in c++) to store which number belongs to which disjoint set. Instead of that, you can use a hashset to store this information. With this and some additional changes, you can easily implement the second operation. I'll leave the implementation to you.
Sorry, I was doing a small mistake in taking input. First time I saw input terminate by using END Of the File(EOF). My code was working fine for one testcase. Now it's working.
Is it accepted ?