#P2420. 让我们异或吧
让我们异或吧
Description
XOR is a special operation, often summarized as addition without carry.
In daily life, xor is also common. For example, for a yes/no question, yes is and no is , then: (A is male) xor (B is male) = whether A and B can become a couple.
Now, we will handle a more complex case. You are given a tree with nodes. Each edge has a weight. There are queries. For each query, find the XOR of all edge weights along the path between two nodes.
Input Format
The first line contains an integer , the number of nodes in the tree. The next lines each contain three integers , indicating there is an edge between and with weight . The next line contains an integer , the number of queries. Each of the next lines contains two integers , asking for the XOR of the edge weights along the path between and .
Output Format
Output lines, each with one integer, the XOR value.
5
1 4 9644
2 5 15004
3 1 14635
5 3 9684
3
2 4
5 4
1 1
975
14675
0
Hint
Constraints:
- For of the testdata, .
- For of the testdata, .
- Edge weights are within the
intrange.
Translated by ChatGPT 5
京公网安备 11011102002149号