#P13279. 「CZOI-R4」生长的树
「CZOI-R4」生长的树
Description
You are Little J's gardener, and you need to help him prune his growing tree, .
is a -ary tree. At time 0, consists of only the root node with ID 1.
Starting from time 1, at each time step, the following events occur in order:
- Growth Phase: For all nodes in that have fewer than children, new child nodes are added until they have exactly children. The IDs of these new nodes can be arbitrarily assigned (they don't need to be ), but must be unique within .
- Pruning Phase: You may perform any number of operations (including zero), where each operation consists of selecting any non-root node of and removing its entire subtree.
Little J provides you with a tree of nodes (rooted at node 1). The goal is to satisfy the following conditions after some time:
- must have exactly nodes with IDs exactly 1 through .
- For all non-root nodes, nodes with the same ID in and must have the same parent.
Your task is to determine:
- The earliest time when these conditions can be satisfied.
- The minimum number of pruning operations required at that time.
Input Format
First line: Two integers and .
Next lines: Pairs describing edges of .
Output Format
Two space-separated integers :
- Earliest possible time to satisfy conditions.
- Minimum operations needed at time .
6 3
1 2
1 5
2 3
2 4
5 6
2 4
Hint
Sample Explanation:
As shown in the figure, after assigning node IDs at times and , and then deleting subtrees of nodes at time , the conditions are satisfied. It can be proven that no better solution exists.

Data Range
This problem uses bundled testing:
- Subtask#1 (): .
- Subtask#2 (): is a perfect -ary tree.(That means every non-leaf nodes have children.)
- Subtask#3 (): .
- Subtask#4 (): .
- Subtask#5 (): No additional constraints.
For all data , , . Here, refers to the number of sons of the -th node in .
京公网安备 11011102002149号