#P10739. [SEERC 2020] Disk Sort
[SEERC 2020] Disk Sort
Problem Description
You have rods. Initially, each rod from to has disks on it, and the number of possible colors does not exceed .
In each operation, you may choose a pair , meaning moving the top disk of rod onto the top of rod (rod must have at least disk, and rod can have at most disks).
You need to construct a valid sequence of operations such that after all operations, the colors of the disks on each rod are all the same, and rod is empty.
Input Format
The first line contains an integer , meaning there are rods.
The next lines each contain integers , where is the color of the -th disk from top to bottom on rod .
Output Format
The first line contains an integer , meaning the number of operations.
Then follow lines, each containing a pair , indicating the move operation.
4
2 3 1 4
2 1 1 4
2 3 3 4
8
3 5
3 5
2 3
2 5
2 3
5 2
5 2
5 2
2
1 2
1 2
1 2
0
Hint
Translated by ChatGPT 5