#P9077. [PA 2018] Poddrzewo
[PA 2018] Poddrzewo
Problem Description
This problem is translated from PA 2018 Round 1 Poddrzewo.
You are given a sequence of length .
Construct an undirected tree with nodes, numbered . The degree of node in this tree must be .
A solution may not exist. You are allowed to perform the following operations to make it solvable:
- Modify the -th number in the sequence.
- Delete the -th number from the sequence.
- Swap the -th and -th numbers in the sequence.
It can be proven that after a finite number of operations, a solution will always exist.
Your task is to minimize the number of times operation 1 is used.
Input Format
The first line contains an integer , the length of the sequence .
The second line contains integers. The -th integer is .
Output Format
The first line contains an integer , the minimum number of times operation 1 is used.
The second line contains an integer , the number of nodes in the tree you construct.
In the next lines, each line contains two integers , indicating an edge between nodes and .
If there are multiple solutions, output any one.
6
2 1 5 3 1 1
0
5
1 2
2 3
1 4
1 5
3
1 2 2
1
3
1 2
2 3
Hint
Explanation for Sample 1
We can delete the -rd number and then change the order of the elements.
The final sequence becomes .
This is a schematic diagram of the constructed tree:

Explanation for Sample 2
We can modify the -rd number, and the final sequence becomes . It can be proven that operation 1 must be used at least time.
This is a schematic diagram of the constructed tree:

Constraints
This problem uses bundled testdata.
For of the testdata:
- .
- .
It is guaranteed that there exists at least one subtask where the minimum value of the number of times operation 1 is used is .
Translated by ChatGPT 5