Codeforces Round 1081 (Div. 2)
E
Swap to Rearrange
Codeforces
2100
原题
← DF →
翻译中…

You are given $2$ arrays, $a$ and $b$, both of length $n$. You can perform the following operation:

翻译中…
  • Choose an index $i$ ($1 \le i \le n$) and swap $a_i$ with $b_i$.
翻译中…

You can perform the operation any number of times (possibly zero), but each index can be chosen by at most one operation. Your task is to make $a$ a rearrangement of $b$ after all operations, or state that it is impossible. You do not have to minimize the number of operations.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($1 \le n \le 10^6$).

翻译中…

The second line of each test case contains $n$ integers $a_1,a_2,\ldots,a_n$ ($1 \leq a_i \leq n$).

翻译中…

The third line of each test case contains $n$ integers $b_1,b_2,\ldots,b_n$ ($1 \leq b_i \leq n$).

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$.

翻译中…

Output

翻译中…

For each test case, output $-1$ if it is impossible to make $a$ a rearrangement of $b$. Otherwise, output two lines in the following format:

翻译中…
  • In the first line, print the number of operations $s$ ($0 \leq s \leq n$).
  • In the second line of each test case, print $s$ numbers – the indices you select in each operation in order. You should guarantee that each index is chosen at most once.
翻译中…

If there are multiple possible answers, you many output any.

翻译中…

Note

翻译中…

In the first test case, the operations performed are swap($a_2, b_2$) and swap($a_4,b_4$), which will make $a = [1,2,3,4]$ and $b = [2,1,4,3]$. Now it is possible to achieve $a$ by rearranging the elements of $b$.

翻译中…

In the second test case, it can be shown that no matter what operations we do, we cannot make $a$ a rearrangement of $b$.

翻译中…

样例

Input #1
4
4
1 1 3 3
2 2 4 4
3
1 2 1
3 3 1
3
1 2 3
2 3 1
4
1 2 2 4
3 1 4 3
Output #1
2
2 4
-1
0

2
3 4
InputCopy OutputCopy
题目信息
题号
2192E
时间限制
5 s
内存限制
512 MB
标签
构造
DFS 及类似
图匹配
图论
贪心
字符串

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。