Universal Cup Judging System

Universal Cup

حد الوقت: 3 s حد الذاكرة: 512 MB مجموع النقاط: 100 قابلة للهجوم ✓
الإحصائيات

Yuki 有一棵有 $2^n$ 個節點嘅樹,節點由 $0$ 到 $2^n - 1$ 編號。第 $i$ 條邊連接節點 $u_i$ 同節點 $v_i$。

設 $\operatorname{lca}_r(u, v)$ 表示當棵樹以節點 $r$ 為根嗰陣,節點 $u$ 同 $v$ 嘅最近公共祖先(LCA)。

你需要幫 Yuki 計算:

$$\bigoplus_{0 \le u < v < 2^n} \operatorname{lca}_{u \oplus v}(u, v)$$

其中 $\oplus$ 表示按位異或(XOR)運算。

輸入格式

本題包含多組測試資料。

第一行包含一個正整數 $t$($1 \le t \le 10^4$),代表測試資料嘅組數。

對於每組測試資料:

  • 第一行包含一個正整數 $n$($1 \le n \le 21$)。
  • 接落嚟嘅 $2^n - 1$ 行,每行包含兩個整數 $u_i, v_i$($0 \le u_i, v_i < 2^n, u_i \neq v_i$)。

保證輸入構成一棵樹,而且所有測試資料入面 $2^n$ 嘅總和唔超過 $2^{21}$。

輸出格式

對於每組測試資料,輸出一行包含一個整數,代表答案。

樣例

樣例輸入 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

樣例解釋

對於第一組測試資料:

  • 當棵樹以節點 $1$ 為根嗰陣,節點 $0$ 同 $1$ 嘅最近公共祖先係節點 $1$,所以答案係 $\operatorname{lca}_1(0, 1) = 1$。

對於第二組測試資料:

  • 我哋對所有點對 $(u, v)$ 計算 $\operatorname{lca}_{u \oplus v}(u, v)$:
    • $(0, 1)$:$0 \oplus 1 = 1$,$\operatorname{lca}_1(0, 1) = 1$。
    • $(0, 2)$:$0 \oplus 2 = 2$,$\operatorname{lca}_2(0, 2) = 2$。
    • $(0, 3)$:$0 \oplus 3 = 3$,$\operatorname{lca}_3(0, 3) = 3$。
    • $(1, 2)$:$1 \oplus 2 = 3$,$\operatorname{lca}_3(1, 2) = 2$。
    • $(1, 3)$:$1 \oplus 3 = 2$,$\operatorname{lca}_2(1, 3) = 2$。
    • $(2, 3)$:$2 \oplus 3 = 1$,$\operatorname{lca}_1(2, 3) = 2$。
  • 異或和係 $1 \oplus 2 \oplus 3 \oplus 2 \oplus 2 \oplus 2 = 2$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.