問題一覧 > 通常問題

No.429 CupShuffle

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 268
作問者 : startcpp / テスター : りあん
お気に入りにしたユーザー ProblemId : 926 / 自分の提出
問題文最終更新日: 2026-06-25 19:11:17
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 150 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。