#P6071. 『MdOI R1』Treequery
『MdOI R1』Treequery
Description
Given an undirected tree with nodes, where each edge has a weight.
Let denote the set of all edges on the simple path between and in the tree. In particular, when , .
You need to answer queries online. Each query gives . Please compute the sum of edge weights of all edges in the set , i.e. the sum of edge weights contained in the intersection of .
In simple terms, you need to find the length of the common part of the simple paths from to every node in .
Input Format
The first line contains two integers , representing the number of nodes in the tree and the number of queries.
The next lines each contain three integers , indicating that there is an edge between and with weight .
The next lines each contain three integers . For the -th query, the actual are obtained by XOR-ing with , respectively, where is the answer to the previous query and is initially .
Output Format
For each query, output one integer per line, representing the answer.
5 4
3 1 2
1 5 1
2 3 3
3 4 4
2 3 5
2 1 7
0 7 7
5 5 2
3
2
6
0
10 10
2 1 9907
3 2 8329
4 2 8402
5 4 3636
6 4 8747
7 4 3080
8 6 780
9 6 5414
10 9 3545
2 10 10
26107 26106 26101
4 9 10
14171 14166 14169
8958 8949 8949
36008 36014 36013
11485 11485 11472
3 9 9
30888 30894 30895
8404 8404 8411
26108
0
14161
8959
36015
11482
0
30892
8402
0
Hint
[Sample 1 Explanation]
The tree in the sample is shown in the figure:

In the explanations below, all query parameters are the real values after XOR with .
For the first query, , , , and is the edge , with total length .
For the second query, , , , and is the edge , with total length .
For the third query, , , , and is the edge set , with total length .
For the fourth query, , , , , and the total length is .
[Constraints]
This problem uses bundled testdata.
| Subtask ID | Special Property | Score | |
|---|---|---|---|
| 1 | 8 | ||
| 2 | 20 | ||
| 3 | None | ||
| 4 | 26 | ||
| 5 |
For of the data, , , , and .
Translated by ChatGPT 5
京公网安备 11011102002149号