#P10604. BZOJ4317 Atm 的树
BZOJ4317 Atm 的树
Background
The problem is from the original BZOJ. We acknowledge that the statement and the original testdata are copyrighted by the original BZOJ or by the problem author who authorized BZOJ to use it. If you are the copyright owner and believe that your rights have been infringed, please contact us.
Atm spent some time working hard on problems about qtree, so his head was full of tree, tree, tree...
Problem Description
So, one night he dreamed that he was locked inside a rooted tree. Each path has edge weights. A mysterious voice told him that there is a distance from each node to other nodes. For each node, he needs to answer: what is the -th smallest distance starting from this node?
If atm cannot answer it, then tomorrow the 4019 alarm clock will not ring, and the whole dorm 4019 may be late, so atm hopes you can help him.
Input Format
The first line contains two integers , representing the number of nodes in the tree being queried, and the in the problem.
The next lines each contain three positive integers , indicating that there is an edge with weight between node and node .
Output Format
Output lines. The -th line indicates the -th smallest distance starting from node .
5 2
1 5 2
1 2 4
2 3 6
2 4 5
4
5
10
9
6
Hint
For all data, , , . The root of the tree is node .
Translated by ChatGPT 5