#P8965. 坠梦 | Falling into Dream
坠梦 | Falling into Dream
Background
The gods toy with the mortal world. So-called fate is nothing more than a die thrown by the gods.
The butterfly that the flower cannot wait for eventually becomes a strange dream, restarting again and again.
The gods’ puppets are strangled time after time; in the name of love, they vanish into the sea of flowers of time.
Behind countless obsessions, there is always a twisted “truth”.
What you promised never appeared. Sleepless all night, perhaps I was just being self-willed, loving this human world once on your behalf.
“The most devout only pray; only the undevout have demands.”
There was never faith; by risking one’s life to save someone, one was fortunate enough to reach heaven.
Problem Description
Given an unrooted tree with nodes, each edge has a non-negative integer weight. The nodes are numbered from to .
For each pair of nodes , define the distance as the XOR sum of edge weights on the unique simple path between and .
Given two nodes , define the value of node as the XOR of the distances from to and from to , i.e.,
$$\operatorname{val}_{x, y}(i) = \operatorname{dis}(x, i) \oplus \operatorname{dis}(y, i) \textsf{。}$$Now there are queries. Each query gives four integers . You need to compute $\displaystyle \bigoplus_{i = l}^{r} \operatorname{val}_{x, y}(i)$, i.e., compute
$$\operatorname{val}_{x, y}(l) \oplus \operatorname{val}_{x, y}(l + 1) \oplus \cdots \oplus \operatorname{val}_{x, y}(r - 1) \oplus \operatorname{val}_{x, y}(r) \textsf{。}$$In the formulas above, denotes the bitwise XOR operator.
Input Format
The first line contains two integers .
The next lines each contain three integers , indicating that there is an edge of weight between and .
The next lines each contain four integers , indicating one query.
Output Format
Output lines, each containing one integer, the answer to the corresponding query.
3 2
1 2 1
2 3 1
1 2 1 3
2 3 2 3
1
0
Hint
Sample Explanation

The tree given by the input is shown in the figure above. For distances between pairs of nodes, we have:
- $\operatorname{dis}(1, 1) = \operatorname{dis}(1, 3) = \operatorname{dis}(2, 2) = \operatorname{dis}(3, 1) = \operatorname{dis}(3, 3) = 0$, and
- $\operatorname{dis}(1, 2) = \operatorname{dis}(2, 1) = \operatorname{dis}(2, 3) = \operatorname{dis}(3, 2) = 1$.
Query : $\operatorname{val}_{1, 2}(1) \oplus \operatorname{val}_{1, 2}(2) \oplus \operatorname{val}_{1, 2}(3) = (0 \oplus 1) \oplus (1 \oplus 0) \oplus (0 \oplus 1) = 1 \oplus 1 \oplus 1 = 1$.
Query : $\operatorname{val}_{2, 3}(2) \oplus \operatorname{val}_{2, 3}(3) = (0 \oplus 1) \oplus (1 \oplus 0) = 1 \oplus 1 = 0$.
Constraints
This problem uses bundled testdata.
| Subtask ID | Score | ||
|---|---|---|---|
| 1 | 24 | ||
| 2 | 14 | ||
| 3 | |||
| 4 | 48 |
For of the data, it is guaranteed that , , , and .
Hint
The maximum I/O size of this problem reaches 60 MiB. Please pay attention to I/O efficiency.
Translated by ChatGPT 5