AmazonOA #380
Location Of Data After Transfers
估计中等可在线判题
考点(AI 标注)哈希计数模拟/实现
The initial positions are pairwise distinct. In order, move the data at position from to position to; the original guarantees that at every step from holds data and to does not. Finally, output all positions that hold data in ascending order.
输入格式
The first line contains n m, the second line contains n initial positions, followed by m lines of from to. The original gives no value bounds; this site adds 0≤n,m≤200000 and each position ID is in −10^9..10^9. The input satisfies the original valid-move guarantee above, so when n=0, m can only be 0.
输出格式
The first line is the number of positions n, and the second line is the positions in ascending order; when n=0 the second line is empty.
样例 1
输入:
4 4
1 2 5 6
1 4
4 7
5 1
7 3
输出:
4
1 2 3 6
样例 2
输入:
1 2
0
0 -1
-1 2
输出:
1
2
样例 3
输入:
0 0
输出:
0
样例说明
The first example ends with 1 2 3 6. The original explanation of the second example mistakenly reused a different set of moves; this site explains it with the actual input 1→4, 4→7, 5→1, 7→3. The remaining examples end with only position 2 and with no positions, respectively.