#P10748. [SEERC 2020] Mistake
[SEERC 2020] Mistake
Problem Description
You have machines. Each machine stores the numbers in an unordered way. When you start a machine, it prints the frontmost number among the numbers stored in that machine, and then deletes it.
Fortunately, you know pairs , meaning that in every machine’s storage, each stored is before .
You also know the output produced by starting machines one by one. For each printed number, determine a plan that specifies which machine it came from, and make sure that the number of occurrences of each number .
There may be multiple feasible solutions; output any one to get accepted.
Input Format
The first line contains three integers $n, k, m\ (1 \leq n, k \leq 5 \times 10^5, 0 \leq m \leq 2.5 \times 10^5, 1 \leq n \times k \leq 5 \times 10^5)$.
Then follow lines, each containing two integers , and it is guaranteed that there is no cycle.
Then one line contains numbers, representing the sequence printed by the machines when they are started in order.
Output Format
Output one valid starting plan.
3 3 2
1 2
1 3
1 1 2 3 3 2 1 2 3
1 2 2 1 2 1 3 3 3
Hint
Translated by ChatGPT 5