#P8025. [ONTAK2015] Związek Harcerstwa Bajtockiego
[ONTAK2015] Związek Harcerstwa Bajtockiego
Problem Description
Given an unrooted tree with nodes, the distance between adjacent nodes is . At the beginning, you are at node . Then you will receive commands one by one. Each command contains two integers and . You need to move toward node along the shortest path within steps (including exactly steps). If you cannot reach within steps, then you stop at the last node you can reach. After each command, output your current position.
Input Format
The first line contains three integers .
The next lines each contain two integers , representing an edge of the tree.
The next lines each contain two integers , representing a command.
Output Format
One line containing integers, where the -th integer is the node you are at after executing the -th command.
3 1 2
1 2
2 3
3 4
1 1
3 2
Hint
For of the data, , , , .
Translated by ChatGPT 5