問題一覧 > 通常問題

No.100 Series Amidakuji

レベル : / 実行時間制限 : 1ケース 5.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 100
作問者 : sugim48
お気に入りにしたユーザー ProblemId : 178 / 自分の提出
問題文最終更新日: 2026-06-25 01:05:06
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 64 (順位表) の他の問題:

Problem Statement

Consider an amidakuji (ladder lottery) consisting of $N$ vertical lines and horizontal lines that horizontally connect adjacent vertical lines.
We call a figure obtained by connecting $2$ amidakuji of exactly the same shape one above the other a "series amidakuji".
The figure below is an example of a series amidakuji.

Given the correspondence between the starting points and ending points of an amidakuji, determine whether there exists a "series amidakuji" that satisfies this correspondence.

Input

$N$
$a_1$ $\ldots$ $a_N$

Line $1$ contains $N(2\leq N\leq50)$, the number of vertical lines.
Line $2$ contains $a_i(1\leq a_i\leq N)$, separated by spaces, which represent the correspondence between the starting points and ending points.
This means that starting from the $i$-th vertical line from the left, you arrive at the $a_i$-th vertical line from the left.
$a_1,\ldots,a_n$ are all distinct.

Output

Print Yes if there exists a "series amidakuji" that satisfies the correspondence between the starting points and ending points, and No otherwise.
Print a newline at the end.

Sample

Sample 1
Input
2
1 2
Output
Yes

One like the figure below exists.

Sample 2
Input
3
2 3 1
Output
Yes

One like the figure below exists.

Sample 3
Input
2
2 1
Output
No

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