問題一覧 > 通常問題

No.2346 Replace!!

レベル : / AI推定難易度 : 2100 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 22
作問者 : ytqm3 / テスター : ぷら shiomusubi496
お気に入りにしたユーザー ProblemId : 9668 / 自分の提出
問題文最終更新日: 2023-06-10 00:34:51
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 392 (順位表) の他の問題:

Problem Statement

Solve the following problem for $T$ test cases.

You are given sequences $A, B$ of length $N$ consisting of integers between $1$ and $N$, inclusive. You may perform the following operation any number of times, possibly $0$.

  • Choose an integer $i\ (1 \le i \le N)$. Replace $A_i$ with $A_{A_i}$.

Determine whether it is possible to make $A$ equal to $B$.

Input

$T$
$\text{case}_1$
$\text{case}_2$
$\vdots$
$\text{case}_T$

Each case is given in the following format.

$N$
$A_1$ $A_2$ $\ldots$ $A_N$
$B_1$ $B_2$ $\ldots$ $B_N$
  • $1 \le T \le 5000$
  • $1 \le N \le 5000$
  • $1 \le A_i,B_i \le N$
  • The sum of $N$ over all cases does not exceed $5000$.
  • All inputs are integers.

Output

Print $T$ lines. The $i$-th line should contain the answer for $\text{case}_i$. For each case, print Yes if it is possible, and No if it is impossible.

Sample

Sample 1
Input
3
3
2 3 1
2 3 2
5
1 1 1 1 1
1 2 3 4 5
5
1 1 2 3 4
1 1 1 1 1
Output
Yes
No
Yes

For the $1$st case: choosing $i=3$ and replacing $A_3$ with $A_{A_3}=A_1=2$ gives $A=(2,3,2)$.

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