問題一覧 > 通常問題

No.26 Shuffle Game

レベル : / AI推定難易度 : 115 / 実行時間制限 : 1ケース 5.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 850
作問者 : なお
お気に入りにしたユーザー ProblemId : 74 / 自分の提出
問題文最終更新日: 2024-05-04 02:59:38
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 26 (順位表) の他の問題:

Problem Statement

Taro and Jiro are playing a game.

There are \(3\) cups on a table. Exactly \(1\) of them is marked with ○,
and the other \(2\) are marked with ×, with the marks not visible from the outside.

The cups are numbered \(1\), \(2\), \(3\) starting from the left as seen from Taro.
First, it is revealed which cup has the ○ mark. After that,
Jiro swaps the positions of cups several times,
and Taro must guess which cup has the ○ mark.

Both during and after the swaps, the cups are always numbered \(1\), \(2\), \(3\) from the left,
and except at the beginning, the marks on the cups cannot be seen.

The input gives the position number of the cup that initially has the ○ mark,
and the position numbers of the cups Jiro swapped.
Output the position number of the cup that finally has the ○ mark.

Input

\(N\)
\(M\)
\(P_1\ Q_1\)
\(P_2\ Q_2\)
\(\dots\)
\(P_M\ Q_M\)

The \(1\)st line contains an integer \(N\ (1 \leq N \leq 3 )\), the position of the cup that initially has the ○ mark.
The \(2\)nd line contains an integer \(M\ (1 \leq M \leq 200)\), the number of times the cups were swapped.
Each of the following \(M\) lines contains space-separated integers \(P_i, Q_i\ (1 \leq P_i,Q_i \leq 3,\ 1 \leq i \leq M,\ P_i \neq Q_i)\), the position numbers of the cups to swap.

Output

Output the position number of the cup that finally has the ○ mark.
Print a newline at the end.

Sample

Sample 1
Input
1
1
1 3
Output
3

Initially, the left \((1)\) cup has the ○ mark. Since the left \((1)\) cup and the right \((3)\) cup are swapped,
the right \((3)\) cup finally has the ○ mark.

Sample 2
Input
1
3
2 3
3 2
2 3
Output
1

It stays in its initial position.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。