#Q136. 「一本通 4.4 练习 1」Dis
「一本通 4.4 练习 1」Dis
Description
Given a tree with nodes, answer multiple queries about the shortest distance between two nodes.
Note: The edges are bidirectional.
Input Format
The first line contains two integers and . represents the number of nodes, and represents the number of queries.
The next lines each contain three integers , , and , indicating that there is an edge between node and node with length .
The following lines each contain two integers and , representing a query for the shortest distance between node and node .
Output Format
Output lines. For each query, output the answer on a separate line.
Sample 1
2 2
1 2 100
1 2
2 1
100
100
Sample 2
3 2
1 2 10
3 1 15
1 2
3 2
10
25
Constraints and Hints
For all data, , , , .