Codeforces Round 981 (Div. 3) |
---|
Finished |
Given a tree with $$$n$$$ vertices rooted at vertex $$$1$$$. While walking through it with her cat Chefir, Sakurako got distracted, and Chefir ran away.
To help Sakurako, Kosuke recorded his $$$q$$$ guesses. In the $$$i$$$-th guess, he assumes that Chefir got lost at vertex $$$v_i$$$ and had $$$k_i$$$ stamina.
Also, for each guess, Kosuke assumes that Chefir could move along the edges an arbitrary number of times:
If Chefir's stamina is $$$0$$$, he cannot make a move of the second type.
For each assumption, your task is to find the distance to the farthest vertex that Chefir could reach from vertex $$$v_i$$$, having $$$k_i$$$ stamina.
$$$^{\text{∗}}$$$Vertex $$$a$$$ is an ancestor of vertex $$$b$$$ if the shortest path from $$$b$$$ to the root passes through $$$a$$$.
The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases.
Each test case is described as follows:
It is guaranteed that the sum of $$$n$$$ and the sum of $$$q$$$ across all test cases does not exceed $$$2\cdot 10^5$$$.
For each test case and for each guess, output the maximum distance to the farthest vertex that Chefir could reach from the starting point $$$v_i$$$ having $$$k_i$$$ stamina.
351 22 33 43 535 13 12 098 11 71 47 34 93 21 53 676 02 36 28 22 49 26 362 12 52 45 64 333 11 36 5
2 1 2 0 5 2 4 5 5 5 1 3 4
In the first example:
Name |
---|