luogu#P7807. 魔力滋生
魔力滋生
Background
Source: Eight Immortals Toasting, which you can click.
- Lü Dongbin — Drunkenly lifts the pot with immense strength.
- Tieguai Li — Spins the elbow and knee, drunk yet real.
- Han Zhongli — Stumbles, hugs the jar, and rams the heart.
- Lan Caihe — Lifts a toast with one hand and breaks the waist block.
- Zhang Guolao — Drunkenly throws the cup and kicks in a chain.
- Cao Guojiu — The immortal toasts and locks the throat.
- Han Xiangzi — Grabs the wrist, strikes the chest, and drunkenly plays the flute.
- He Xiangu — Bends the waist to offer wine, drunkenly swaying her steps.
Problem Description
You are given a tree with nodes, where the number of nodes connected to any node is at most .
Now perform operations on nodes in order:
- Randomly choose an integer .
- Create new nodes, and connect each new node to with an edge.
Obviously, after all operations, the result is still a tree , whose number of nodes is .
Given the resulting tree and its number of nodes , reconstruct the original tree . If there are multiple solutions, output any one that makes as large as possible.
Note that during reconstruction and output, we only care about the shape of the tree, not the relative numbering of nodes.
Input Format
The first line contains two positive integers , representing the number of nodes in tree and the lower bound of the random number .
Lines each contain two positive integers , representing an edge in .
Output Format
The first line outputs one positive integer , the number of nodes in the constructed tree .
Lines each output two positive integers , representing an edge in .
The output must satisfy: .
5 1
1 2
1 3
1 4
1 5
1
7 0
1 2
1 3
1 4
1 5
1 6
1 7
3
1 2
1 3
9 1
1 2
2 3
1 4
1 5
2 6
2 7
3 8
3 9
3
1 2
2 3
Hint
Sample Explanation
In sample , only node can be in tree : its corresponding is .
In sample , nodes are in tree : node corresponds to being , and nodes correspond to being .
In sample , nodes are in tree : their randomly chosen are all .

Sample provides an illustration. The red nodes represent the nodes in tree , and all nodes in the figure are on .
Constraints
| Subtask | Score | |
|---|---|---|
| Hack |
Note: Subtask 4 is unscored Hack testdata. Only if you pass all subtasks will it be considered AC.
For of the data: , and the input guarantees that a solution exists.
Afterword
Aurora magic flowers are so cute

Translated by ChatGPT 5