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 . There are allowed types of operations . It is guaranteed that no operation type is repeated. Each operation is described by , , meaning you may swap the number at index with the number at index . You may apply operations to the permutation any number of times. Please output one sequence of operations that turns the original permutation into , , , , . 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 , .
The second line contains integers, describing the permutation.
The next lines each contain two integers; the -th line describes the -th allowed operation.
Output Format
The first line contains an integer , the minimum number of operations.
The next lines each contain one integer, indicating that you perform the -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