POLICEMEN - Police Men
There is a country of n cities and n-1 bidirectional roads you can go from any city to another using its roads
You are a police man and there is a theif who is going to escape from the country using an airport in city 1 you are given m queries which of type "a b" which means the thief is in city a and you are in city b you should find if it's possible to catch him before he escape or not and find the city which you will catch him in if it's possible.
You are moving at the same speed the thief moving at and the thief is taking the shortest path to city 1
If you arrived in a city in the same time as the thief you can catch him in it if you arrived before him you can wait for him
If there is more than one city you can catch him in print the nearest one to you.
the first line contains an integer n (1 ≤ n ≤ 104) then n-1 lines each contains two integers which means there is a road between city u and v
then an intger q (1 ≤ q ≤ 104) and q lines of form a b (1 ≤ a , b ≤ n) which are the thief's position and your position
for each query print YES then a space then the city which you will catch him in if it's possible otherwise print NO
"nearest one to you."
Sorry but there were a mistake in the data set but I couldn't rejudge the solutions please resubmit your solutions