Universal Cup Judging System

Universal Cup

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

ליוקי יש עץ עם $2^n$ צמתים, הממוספרים מ-$0$ עד $2^n - 1$. הקשת ה-$i$ מחברת בין צומת $u_i$ לצומת $v_i$.

נסמן ב-$\operatorname{lca}_r(u, v)$ את האב הקדמון המשותף הנמוך ביותר (LCA) של הצמתים $u$ ו-$v$ כאשר שורש העץ הוא בצומת $r$.

עליכם לעזור ליוקי לחשב את:

$$\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$.

עבור מקרה הבדיקה השני:

  • נחשב את $\operatorname{lca}_{u \oplus v}(u, 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$.
  • סכום ה-XOR הוא $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.