#955
Gold III
POSLOZI
시간 제한
1.5s
메모리 제한
32MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Author: Marko Ivanković “Arrange” is a planetary popular Flash game. In “Arrange” the player is given a permutation of numbers 1 to N and a list of allowed swaps. He then has to perform a sequence of swaps that transforms the initial permutation back to the ordered sequence 1,2,3,4,5...N. In order to break the high score list, you need to perform the minimal amount of swaps possible. You can't do that, but you can write a program that does it for you!

입력

The first line of input contains two integers, N (1 ≤ N ≤ 12), the length of the initial sequence and M (1 ≤ M ≤ N*(N – 1) / 2) number of allowed swaps. The second line of input contains a permutation of number 1 to N. The next M lines contain descriptions of allowed swaps. If the line contains numbers A and B you are allowed to swap the A-th number with the B-th number. The input will never contain two identical swaps. Note: the test data shall be such that the solution, not necessarily unique, will always exist.

출력

In the first line of input print the minimal number of swaps, X. In the next X lines print the required swaps, in order. In each line print the index of the swap performed. Swaps are numbered increasingly as they appear in the input, starting from 1. Author: Marko Ivanković

예제 입력 1

2 1
2 1
1 2

예제 출력 1

1

예제 입력 2

3 2
2 1 3
1 3
2 3

예제 출력 2

3

예제 입력 3

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

예제 출력 3

0
코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Gold III1명 투표· 약 1개월 전
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.