logo AlgoBeat OnlineJudge
登录 注册

#217367. [ICPC 2026 Xi'an I] XOR and LCA

内存限制:512 MiB 时间限制:4000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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:

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.

样例

样例输入 1

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

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 .