#P17304. [ICPC 2026 Xi'an I] XOR and LCA
[ICPC 2026 Xi'an I] XOR and LCA
题目描述
Yuki has a tree with nodes, labeled from to . The -th edge connects node and node .
Let denote the lowest common ancestor of nodes and when the tree is rooted at node . You need to help Yuki calculate:
$$\bigoplus_{0 \le u < v < 2^n} \operatorname{lca}_{u \oplus v}(u, v)$$where denotes the bitwise XOR operation.
输入格式
This problem contains multiple test cases.
The first line contains a positive integer , representing the number of test cases.
For each test case:
- The first line contains a positive integer .
- The next lines each contain two integers .
It is guaranteed that the input forms a tree, and the sum of over all test cases does not exceed .
输出格式
For each test case, output a single line containing an integer representing the answer.
4
1
0 1
2
0 1
1 2
2 3
3
0 1
0 2
0 3
0 4
0 5
0 6
0 7
3
4 5
2 6
3 7
0 2
1 5
2 7
6 4
1
2
0
4
提示
For the first test case:
- When the tree is rooted at node , the lowest common ancestor of nodes and is node , so the answer is .
For the second test case:
- We calculate for all pairs :
- : , .
- : , .
- : , .
- : , .
- : , .
- : , .
- The XOR sum is .