Chasing Game
题号:NC252834
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Colin and Eva are playing a chasing game on a given tree with n nodes, indexed from 1 to n.

Colin knows that Eva will start from node S at time 0 , and move towards her destination node T at the speed of 1 edge per second. (i.e. Assuming that the path from S to T is p_0, p_1, \cdots, p_k,\text{ } p_0 = S, p_k = T , then Eva will arrive at node p_i at time i ) After arriving at node T, Eva will stay still there until she is caught by Colin.

Now Colin wants to chase Eva. At time 0, Colin is at node S' ; every second Colin can choose to stay still at the current node or to move once along the edge connected to the current node, and arrive at the other node of this edge at the end of this second.

Colin wants to chase Eva as soon as possible. Can you tell him what's the minimum time that Colin and Eva will be at the same node.

Colin and Eva will play this game q times, you need to tell Colin the minimum time for every game, and the corresponding index of the node.

输入描述:

The first line contains two integers n, q \text{ } ( 1 \le n,q \le 2 \times 10^5) , representing the number of nodes and the times Eva and Colin play the chasing game for.

For the following n - 1 lines, each line contains two integers u_i, v_i \text{ } ( 1 \le u_i, v_i \le n, u_i \neq v_i) , representing that there is an edge connecting node u_i and node
v_i . It's guaranteed that the given edges form a tree.

For the following q lines, each line contains three integers S_i,T_i,S'_i \text{ } (1 \le S_i, T_i, S'_i \le n,S_i \neq T_i ) , representing the start point for Eva, the end point for Eva, and the start point for Colin.

输出描述:

Output q lines.

The i-th line contains two integers t_i,p_i , representing the minimum time that Colin and Eva will be at the same node is t_i , and the index of this node is p_i .

It can be proved there is only one possible value of p_i for each game.
示例1

输入

复制
5 3
1 2
1 3
3 4
3 5
4 1 2
3 5 1
5 2 4

输出

复制
2 1
2 5
1 3