Tree
Very easy
Execution time limit is 2 seconds
Runtime memory usage limit is 1,024 megabytes
A weighted tree is given. Find the distance between two specified vertices.
Input
The first line contains the number of nodes in the tree. Nodes are numbered from to . Each of the following lines consists of three integers representing an edge with weight , connecting nodes and . The next line contains the number of queries . Each of the next lines contains two integers — the numbers of vertices between which the distance needs to be computed.
Output
For each query print the distance between the nodes with the given numbers.
Examples
Input #1
Answer #1
Submissions 2K
Acceptance rate 26%