Problem B
Fakebool Quick-Find

The social network Fakebool has had a lot of problems with fake news spread by fake user accounts. You have been hired along with a team of consultants to shut them down.
By using a 100% fail-proof machine learning technique, a
colleague has managed to identify pairs of profiles on the
network which definitely are managed by the same individual.
You are interested in quickly determining what is the
original user account of the person behind a username.
You define the oldest account created by a person to be his
original account; each account is associated with a unique
identifier (ID) from
This all reminds you of a course you once took in algorithms and data structures, and something called Union Find. In particular, there was an implementation you vividly recall named quick-find which answered such questions in constant time! You decide to implement it, and test it with your colleague’s data.
Input
The first line of input consists of two integers
Constraints
Output
Output a single line with
Sample Input 1 | Sample Output 1 |
---|---|
6 3 3 1 4 5 0 5 |
0 1 2 1 0 0 |