ENIGMA-0x03 (2025) - S3 / A0 Waiting for the Package
View as PDFWaiting for the Package

It's 19:55, five minutes before the local branch of our favorite courier company closes, and Totos rushes to get a good spot in the queue. But when he arrives, he sees that the line is very long, and he'll have to wait quite a while to pick up his package. Then more customers arrive -some of whom know people already in line-so they "cut in" and join not at the end, but directly behind someone they know. Unfortunately, Totos doesn't know anyone, so he is destined to be the last to enter the store. While waiting, he tries to figure out the order in which the other customers will enter. Can you help him?
Input Data (STDIN)
On the first line of input, positive integers
and
are given: the number of customers already in the queue, and the total number of customers, respectively.
On the second line,
distinct integers are given, corresponding to the
people already in the queue.
The next
lines each contain two integers: the first corresponds to a new customer not yet in the queue, and the second to a customer already in the queue, behind whom the new customer will join.
Output Data (STDOUT)
The program should print the final order of customers on separate lines.
Example
Input (STDIN)
3 5
1 2 3
4 1
5 2
Output (STDOUT)
1
4
2
5
3
Subtasks
- For
of the points:
- For
of the points:
Comments