#P16609. [SYSUCPC 2025] Road2
[SYSUCPC 2025] Road2
题目描述
The highway system of Province G can be viewed as a weighted undirected graph with nodes and edges. Each edge represents a segment of the highway, and each node represents a city. Every highway segment is bidirectional. The -th highway segment connects the two cities and , with a length of kilometers.
is currently commuting in Province G. Her car consumes one unit of fuel per kilometer traveled. Any city has a gas station where the car's fuel tank can be fully refilled, and the fuel consumption of 's car while driving within the city is negligible. has planned trips. The -th trip starts from city and ends at city . She wants to know the minimum fuel tank capacity required for this trip.
However, she has not decided on and but only knows that and lie within the interval . Specifically, for all , Miss Orange wants to know the sum of the minimum fuel tank capacities required to travel from to . Formally, let denote the fuel tank capacity required for a trip starting at and ending at . You need to output .
Since she needs to consider her next plan based on the current one, certain constraints will be imposed on you in the problem.
输入格式
The first line contains two integers and .
The next lines each contain three integers , representing an edge between and with a weight of . It is guaranteed that the graph is connected.
Then, one line contains an integer .
The next lines each contain two integers , representing the encrypted queries. Each time, you need to XOR the current and with the previous answer to obtain the real and .The data guarantees that the real and satisfy .
输出格式
Output lines, each containing one integer representing the answer.
5 10
1 2 13
1 3 13
1 4 12
4 5 11
4 4 7
4 2 10
4 5 13
1 4 8
2 4 8
3 4 8
5
4 4
2 4
28 29
10 10
1 5
0
24
11
0
92