#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 cities on Y Island, connected by 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, and , representing the number of cities and the number of gatherings, respectively.
The next lines each contain two positive integers and , indicating a road between city and city . Cities are numbered from to .
The following lines each contain three positive integers, representing the locations of Little Coco, Little Kaka, and Little YY for a gathering.
Output Format
Output lines, each containing two numbers and , separated by a space. For the -th gathering, is the chosen city's number, and 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 of the data, ;
For of the data, .