TOLLS
시간 제한0.25초메모리 제한1024 MB
가중치가 있는 트리에서 각 질의 [l, r]마다 최대 간선 가중치가 [l, r]에 속하는 모든 단순 경로의 최대 간선 가중치 합을 구한다.
문제
In the country named Ivo, there are cities connected by bidirectional highways and you can get from any city to any other city using the highways. Each highway connects two different cities and and it has a toll tax , . We will call "trip" a simple path (not containing duplicate cities) along the highways between two different cities and . The costs for the trips in the country Ivo have been reduced and instead of paying the sum of the tolls along the trip, only one toll is paid, which is a maximal toll for a highway along the trip.
Ivaylo is responsible for the profits in the country. The government asked Ivaylo questions for the sum of the costs of all the trips with costs in the interval , . It is guaranteed that the first question is for the sum of the costs of the trips between every two different cities, i.e. and . Ivaylo cannot handle this task, calculating by hand, and because he cannot work with computers he requires that you write a program tolls, which calculates the answers to the questions.
입력
The first line of the standard input contains two positive integers and -- the number of cities in the country Ivo and the number of questions given to Ivaylo. Each of the next lines contains three positive integers , which describe a highway between the cities and with toll . Each of the rest lines contains two positive integers , which describe the questions given to Ivaylo.
출력
For each question, in input order, output on a separate line the sum of the costs of the trips that are in the interval .
제한
힌트
Illustration of the cities and the highways:

- The count of the trips with cost is : .
- The count of the trips with cost is : .
- The count of the trips with cost is : .
- The count of the trips with cost is : .
- The count of the trips with cost is .
- The answer to the first question is: .
- The answer to the second question is: .
- The answer to the third question is: .
- The answer to the fourth question is: .
- The answer to the fifth question is: .