AmazonOA #197
Get Final Locations
Estimated EasyJudge-ready
Topics (AI-labelled)HashingSimulation
Initially there are n distinct data positions. In input order, move the data at position from to position to; it is guaranteed that from currently holds data and to currently does not. Output all final positions in ascending order.
Input
The first line contains n m, the second line the initial positions, followed by m lines from to. This site uses 1≤n≤100000, 0≤m≤100000, positions 0..10^9.
Output
Output the n final positions in strictly ascending order, separated by spaces.
Example 1
Input:
2 2
1 3
1 2
2 4
Output:
3 4
Example 2
Input:
2 0
2 5
Output:
2 5
Example 3
Input:
1 2
0
0 10
10 0
Output:
0
Example notes
The answers are 3 4, 2 5 and 0; the third example shows that data may move back to a position that was vacated.
Editorial
Loading solution…