Universal Cup Judging System

Universal Cup

時間限制: 3 s 記憶體限制: 512 MB 總分: 100 可 Hack ✓
统计

Yuki hat einen Baum mit $2^n$ Knoten, die von $0$ bis $2^n - 1$ nummeriert sind. Die $i$-te Kante verbindet Knoten $u_i$ und Knoten $v_i$.

Sei $\operatorname{lca}_r(u, v)$ der tiefste gemeinsame Vorfahre (Lowest Common Ancestor) der Knoten $u$ und $v$, wenn der Baum bei Knoten $r$ gewurzelt ist.

Du musst Yuki dabei helfen, Folgendes zu berechnen:

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

wobei $\oplus$ die bitweise XOR-Operation bezeichnet.

Eingabe

Dieses Problem enthält mehrere Testfälle.

Die erste Zeile enthält eine positive ganze Zahl $t$ ($1 \le t \le 10^4$), die die Anzahl der Testfälle angibt.

Für jeden Testfall:

  • Die erste Zeile enthält eine positive ganze Zahl $n$ ($1 \le n \le 21$).
  • Die nächsten $2^n - 1$ Zeilen enthalten jeweils zwei ganze Zahlen $u_i, v_i$ ($0 \le u_i, v_i < 2^n, u_i \neq v_i$).

Es wird garantiert, dass die Eingabe einen Baum bildet und die Summe von $2^n$ über alle Testfälle $2^{21}$ nicht überschreitet.

Ausgabe

Gib für jeden Testfall eine einzelne Zeile mit einer ganzen Zahl aus, die die Antwort darstellt.

Beispiel

Beispieleingabe 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

Beispielausgabe 1

1
2
0
4

Hinweis

Für den ersten Testfall:

  • Wenn der Baum bei Knoten $1$ gewurzelt ist, ist der tiefste gemeinsame Vorfahre der Knoten $0$ und $1$ der Knoten $1$, also lautet die Antwort $\operatorname{lca}_1(0, 1) = 1$.

Für den zweiten Testfall:

  • Wir berechnen $\operatorname{lca}_{u \oplus v}(u, v)$ für alle Paare $(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$.
  • Die XOR-Summe beträgt $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.