luogu#P5183. [COCI 2009/2010 #2] POSLOZI

[COCI 2009/2010 #2] POSLOZI

Problem Description

Translated from COCI 2009.11 T5 “POSLOZI”.

You are given a permutation of length NN (1N12)(1 \le N \le 12). There are MM allowed types of operations (1MN×(N1)2)(1 \le M \le \frac{N \times (N - 1)}{2}). It is guaranteed that no operation type is repeated. Each operation is described by LL, RR, meaning you may swap the number at index LL with the number at index RR. You may apply operations to the permutation any number of times. Please output one sequence of operations that turns the original permutation into 11, 22, 33, \ldots, NN. If there are multiple solutions, output one with the minimum number of operations. If there are still multiple, output any one of them.

Input Format

The first line contains two integers NN, MM.
The second line contains NN integers, describing the permutation.
The next MM lines each contain two integers; the ii-th line describes the ii-th allowed operation.

Output Format

The first line contains an integer ope_cnt\mathit{ope\_cnt}, the minimum number of operations.
The next ope_cnt\mathit{ope\_cnt} lines each contain one integer, indicating that you perform the ii-th allowed operation.

2 1
2 1
1 2
1
1
3 2
2 1 3
1 3
2 3
3
2
1
2
5 5
1 2 3 4 5
1 5
2 5
1 4
1 1
3 5
0

Hint

Translated by ChatGPT 5