QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 1024 MB Total points: 100

#8948. 報復社會

統計

給定一棵以 $1$ 為根的有根樹,第 $i$ 個點的父親是 $p_i$,其顏色是 $col_i$,保證 $col_i\in \{0,1\}$。

Alice 和 Bob 在這棵樹上玩遊戲。兩人輪流操作,Alice 先手。每次操作選取一個點 $x$,滿足 $x=1$ 或 $p_x$ 已經被刪除,然後把 $x$ 刪除。

如果最後一個被刪除的點的顏色是 $0$ 則 Alice 勝,否則 Bob 勝。兩人皆會為了勝利執行最優操作。

給出 $T$ 組數據,對每組數據判斷勝者是誰。

輸入格式

第一行一個正整數 $T$,表示數據組數。每組數據的格式如下:

  • 第一行一個正整數 $n$。
  • 第二行 $n-1$ 個正整數 $p_2,p_3,\cdots,p_n$。
  • 第三行 $n$ 個非負整數 $col_1,col_2,\cdots,col_n$。

輸出格式

對每組數據輸出一行 AliceBob,表示勝者。

範例

範例輸入 1

3
2
1
1 0
5
1 2 2 1
0 0 0 1 0
8
1 2 2 2 1 6 1
1 0 0 0 1 0 1 0

範例輸出 1

Alice
Bob
Alice

資料範圍

本題採用子任務捆綁測試。

對於所有數據,保證 $1\le T\le 10000, 1\le \sum n\le 5\times 10^5, 1\le p_i\lt i, 0\le col_i\le 1$。

Subtask $1$ ($20$ pts): 保證 $T=1, n\le 20$。

Subtask $2$ ($30$ pts): 保證對於所有 $i$,滿足 $i=1\lor p_i=1\lor p_{p_i}=1$。

Subtask $3$ ($20$ pts): 保證對於所有 $i$,要麼 $i$ 是葉子,要麼 $i$ 的子樹大小為偶數。

Subtask $4$ ($30$ pts): 無特殊限制。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

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.