프로그램 명: coci_sor(special judge)
제한시간: 1 초

//sj 가 아직........

[문제요약] 소팅 기계가 수행할 수 있는 동작은 사이클릭 스왑이다.

4 , 1 , 5 , 2 , 3 순으로 된 나열에서 2 , 1 , 3 의 사이클릭 스왑이란

결과는 1 , 5 , 4 , 2 ,3 이 된다.

문제는 최소의 사이클릭 동작 수로 모든 나열을 정렬하는 게 문제이다. 답이 여러개인 경우 그 중 하나를 출력한다.


In order to automate his workload at the factory, Mirko wants to put up to use his old boxsorting robot. There are N boxes in the factory, and each box is labelled with an unique integer in range 1 to N. Mirko's task is to sort the boxes in the ascending order of their labels.

Sorting robot can only perform one specific operation: given the sequence of positions, robot can do a cyclic swap of boxes at those positions. Given sequence does not contain any position more than once.

For example, let's assume that the boxes are currently in order [4, 1, 5, 2, 3], and Mirko provides his robot with the sequence [2, 1, 3]. Robot will then rearrange the boxes so that the second box will go to position 1, first box will go to the position 3, and the third one will take the position 2. Obtained sequence of labels is [1, 5, 4, 2, 3].

Write a program that will sort the boxes using the minimal number of operations. Each sequence given to the robot can be arbitrary long.

입력

출력

NOTE: There may be multiple solutions and you can output any of them.

입출력 예

input 

3 
3 2 1 

output 

1 
2: 3 1

input 

5 
2 3 1 5 4 

output 

2 
3: 1 2 3 
2: 5 4

input 

5 
1 2 3 4 5 

output 

0
출처:coci

[질/답] [제출 현황] [푼 후(0)]
[ 채 점 ] [홈으로]  [뒤 로]