AdvancedRating 1700
Distance in a Tree
For each query (u, v), print the number of edges on the path between u and v in the tree.
Input
n; n − 1 edges; q; q lines 'u v'.
Output
q lines.
Sample 1
Input
5 1 2 1 3 3 4 3 5 3 2 4 4 5 1 1
Output
3 2 0
Sample 2
Input
3 1 3 3 2 20 1 3 3 1 3 3 1 2 3 3 1 2 1 1 2 3 1 1 1 3 1 1 3 3 2 1 2 2 3 2 1 2 3 2 2 2 3 1 3 3
Output
1 1 0 2 0 2 0 1 0 1 0 0 2 0 1 2 1 0 1 0
Output appears here