#abc296f. F - Simultaneous Swap

F - Simultaneous Swap

Score : 500500 points

问题描述

你有两个包含 NN 个数的序列:A=(A1,A2,,AN)A=(A_1,A_2,\ldots,A_N)B=(B1,B2,,BN)B=(B_1,B_2,\ldots,B_N)

高桥可以任意次数(包括零次)重复以下操作:

选择三个两两不同的整数 iijjkk,满足 1i,j,kN1\leq i, j, k\leq N
AA 中的第 ii 个元素和第 jj 个元素交换,并将 BB 中的第 ii 个元素和第 kk 个元素交换。

如果存在一种方法使得高桥通过重复执行该操作使 AABB 相等,则输出 Yes;否则,输出 No

这里所说的 AABB 相等是指,对于所有满足 1iN1\leq i\leq NiiAA 中的第 ii 个元素与 BB 中的第 ii 个元素相等。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given two sequences of NN numbers: A=(A1,A2,,AN)A=(A_1,A_2,\ldots,A_N) and B=(B1,B2,,BN)B=(B_1,B_2,\ldots,B_N).

Takahashi can repeat the following operation any number of times (possibly zero).

Choose three pairwise distinct integers ii, jj, and kk between 11 and NN.
Swap the ii-th and jj-th elements of AA, and swap the ii-th and kk-th elements of BB.

If there is a way for Takahashi to repeat the operation to make AA and BB equal, print Yes; otherwise, print No.
Here, AA and BB are said to be equal when, for every 1iN1\leq i\leq N, the ii-th element of AA and that of BB are equal.

Constraints

  • 3N2×1053 \leq N \leq 2\times 10^5
  • 1Ai,BiN1\leq A_i,B_i\leq N
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \ldots ANA_N

B1B_1 B2B_2 \ldots BNB_N

Output

Print Yes if there is a way for Takahashi to repeat the operation to make AA and BB equal, and print No otherwise.

Sample Input 1

3
1 2 1
1 1 2

Sample Output 1

Yes

Performing the operation once with (i,j,k)=(1,2,3)(i,j,k)=(1,2,3) swaps A1A_1 and A2A_2, and swaps B1B_1 and B3B_3,
making both AA and BB equal to (2,1,1)(2,1,1). Thus, you should print Yes.

Sample Input 2

3
1 2 2
1 1 2

Sample Output 2

No

There is no way to perform the operation to make AA and BB equal, so you should print No.

Sample Input 3

5
1 2 3 2 1
3 2 2 1 1

Sample Output 3

Yes

Sample Input 4

8
1 2 3 4 5 6 7 8
7 8 5 6 4 3 1 2

Sample Output 4

No

update @ 2024/3/10 12:18:51