Given an array that stores all number from 1 to N (both inclusive and sorted).
The task is to do following operations on array elements :
UNION X Z : Do union of x and z. Parent of z will become parent of x.
FIND X: Find the parent of X and print it.
Note: Initially all are the parent of themselves.
First line consists of T test cases. First line of every test case consists of 2 integers N and K, denoting the size of array and number of queries. Second line consists of K queries, consisting of a string UNION or FIND , for union input two integers as input and to find take one integer as input.
For every FIND query print its parent.
FIND 4 FIND 1 UNION 3 1 FIND 3
4 1 1
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.