No.429 CupShuffle
Problem Statement
You are given how $N$ cups (cup $1$ to cup $N$) were swapped and their final arrangement.
Determine the positions of the $2$ cups swapped in the $X$-th swap.
The setting is as follows.
・Initially, cup $i$ was at position $i$.
・In the $k$-th swap ($1 \le k \le K$, $k \neq X$), the cups at positions $A_k$ and $B_k$ were swapped.
・In the end, cup $C_i$ was at position $i$.
Input
$N\ K\ X$ $A_1\ B_1$ $A_2\ B_2$ $\dots$ $A_K\ B_K$ $C_1\ C_2\ \dots\ C_N$
$2 \le N \le 100000$
$1 \le K \le 100000$
$1 \le X \le K$
For $i \neq X$, $1 \le A_i \lt B_i \le N$
For $i = X$, $A_i$ = ?, $B_i$ = ?
$1 \le C_i \le N$
$C_i$ are pairwise distinct
An answer exists
Hint
In case $1$ to case $10$, $N \le 100$ and $K \le 1000$ are satisfied.
The answer is uniquely determined.
Output
Output in ascending order.
That is, output so that $A_X \lt B_X$ is satisfied.
Print a newline at the end.
Sample
Sample 1
Input
3 6 4 1 3 1 2 2 3 ? ? 2 3 1 3 1 2 3
Output
1 3
If the cups at positions 1, 3 are swapped in the 4-th swap, the arrangement of the cups changes as follows.
123
321
231
213
312
321
123
Sample 2
Input
4 3 3 1 2 3 4 ? ? 2 3 4 1
Output
2 4
Sample 3
Input
5 7 1 ? ? 3 5 2 4 1 3 2 3 1 4 4 5 5 1 4 3 2
Output
2 5
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
startcpp
りあん