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 TT with nn nodes, where the number of nodes connected to any node is at most 22.

Now perform operations on nodes u=1nu = 1 \sim n in order:

  • Randomly choose an integer x(k)x(\ge k).
  • Create xx new nodes, and connect each new node to uu with an edge.

Obviously, after all operations, the result is still a tree TT', whose number of nodes is m=n+xm = n + \sum x.

Given the resulting tree TT' and its number of nodes mm, reconstruct the original tree TT. If there are multiple solutions, output any one that makes n\color{black}n 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 m,km, k, representing the number of nodes in tree TT' and the lower bound of the random number xx.

Lines 2m2 \sim m each contain two positive integers u,vu, v, representing an edge in TT'.

Output Format

The first line outputs one positive integer nn, the number of nodes in the constructed tree TT.

Lines 2n2 \sim n each output two positive integers u,vu, v, representing an edge in TT.

The output u,vu, v must satisfy: 1u,vn1 \le u, v \le n.

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 #1\#1, only node 11 can be in tree TT: its corresponding xx is 44.

In sample #2\#2, nodes 1,2,31, 2, 3 are in tree TT: node 11 corresponds to xx being 44, and nodes 2,32, 3 correspond to xx being 00.

In sample #3\#3, nodes 1,2,31, 2, 3 are in tree TT: their randomly chosen xx are all 22.

Sample #3\#3 provides an illustration. The red nodes represent the nodes in tree TT, and all nodes in the figure are on TT'.

Constraints

Subtask Score x=x=
11 3030 00
22 11
33 4040
44 00 Hack

Note: Subtask 4 is unscored Hack testdata. Only if you pass all subtasks 141 \sim 4 will it be considered AC.

For 100%100\% of the data: 1m105,k[0,m)1 \le m \le 10^5, k \in [0, m), and the input guarantees that a solution exists.


Afterword

Aurora magic flowers are so cute \sim

Translated by ChatGPT 5