#Q138. 「一本通 4.4 练习 3」聚会

「一本通 4.4 练习 3」聚会

Description

Original source: AHOI 2008

Y Island is renowned for its beautiful scenery, mild climate, and abundant resources. There are NN cities on Y Island, connected by N1N-1 roads. Each road links two cities. Fortunately, Little Coco can traverse all cities on the island via these roads. Interestingly, the cost of traveling through each road is the same.

Little Coco, Little Kaka, and Little YY often plan gatherings. For each gathering, they choose a city such that the total cost for all three to reach it is minimized.

Since they anticipate many such gatherings, selecting a location each time becomes tedious. Thus, they delegate this task to you. They will provide you with the map and their respective locations before each gathering, and you are to determine the optimal meeting point for each occasion.

Input Format

The first line contains two positive integers, NN and MM, representing the number of cities and the number of gatherings, respectively.

The next N1N-1 lines each contain two positive integers AA and BB, indicating a road between city AA and city BB. Cities are numbered from 11 to NN.

The following MM lines each contain three positive integers, representing the locations of Little Coco, Little Kaka, and Little YY for a gathering.

Output Format

Output MM lines, each containing two numbers PP and CC, separated by a space. For the ii-th gathering, PP is the chosen city's number, and CC is the total cost, measured in the number of roads traveled.

Sample 1

6 4
1 2
2 3
2 4
4 5
5 6
4 5 6
6 3 1
2 4 4
6 6 6

5 2
2 5
4 1
6 0

Data Range and Hints

For 40%40\% of the data, 1N,M2×1031\le N,M\le 2\times 10^3;

For 100%100\% of the data, 1N,M5×1051\le N,M\le 5\times 10^5.