ADA University - February 12 - LCA
Going to movie
Chip'n'Dale are helping everyone on the country iLandia. One upon time after successful ending of their missions they decided to go to the cinema. But the trouble. There is only one cinema in ILandia, which is situated in capital. Chip eds his adventure in city x and Dale in city y. There is a lack of time till the begin of film session, that is why both of them have decided to order a taxi. Unfortunately our heroes doesn't earn a lot of money from their work. Both of them want to spend as small as possible. Chip can share the cab with Dale and Dale can do the same, but they need to be in one city. In order to that all taxi drivers in iLandia have the same fixed rate for one km. That means that they will split cost for the way which they spend together. You have few scenario of ending adventure of Chip'n'Dale in a different cities. You need to calculate minimum sum of money which they need to get to cinema (for each scenatio).
There is only one road between two city. The distance between two neighboring cities is 1 km. The capital always have number 1.
The first line contains two positive integers: the number of cities n (1 ≤ n ≤
105) in iLindia and the rate Price (1 ≤ Price ≤
104) in cab per 1 km. In the next n - 1 lines 2 positive integers x and y (1 ≤ x, y ≤ n) are given, they describe the road between city x and city y. All roads are two-way. The next line contains the number of scenarios q (1 ≤ q ≤
105). Each scenario starts with city numbers c and d (1 ≤ c, d ≤ n) where Chip'n'Dale will finish their adventures.
Print two numbers - amount of money spent Chip and Dale, with precision no less than
3 2 1 2 1 3 3 2 3 1 2 1 3
2.00000 2.00000 0.00000 2.00000 0.00000 2.00000