I hope you know the beautiful Union-Find structure. In this problem, you're to implement something similar, but not identical.
The data structure you need to write is also a collection of disjoint sets, supporting 3 operations:
1 p qUnion the sets containing p and q. If p and q are already in the same set, ignore this command.
2 p qMove p to the set containing q. If p and q are already in the same set, ignore this command
3 pReturn the number of elements and the sum of elements in the set containing p.
Initially, the collection contains n sets: {1}, {2}, {3}, ..., {n}.5 7
1 1 2
2 3 4
1 3 5
3 4
2 4 1
3 4
3 3
3 12
3 7
2 8