#Q136. 「一本通 4.4 练习 1」Dis

「一本通 4.4 练习 1」Dis

Description

Given a tree with nn nodes, answer multiple queries about the shortest distance between two nodes.

Note: The edges are bidirectional.

Input Format

The first line contains two integers nn and mm. nn represents the number of nodes, and mm represents the number of queries.

The next n1n-1 lines each contain three integers xx, yy, and kk, indicating that there is an edge between node xx and node yy with length kk.

The following mm lines each contain two integers xx and yy, representing a query for the shortest distance between node xx and node yy.

Output Format

Output mm 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, 2n1042\le n\le 10^4, 1m2×1041\le m\le 2\times 10^4, 0<k1000\lt k\le 100, 1x,yn1\le x,y\le n.