QOJ.ac

QOJ

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

#8948. Anti-social behavior

统计

Given a rooted tree with $1$ as the root, the parent of node $i$ is $p_i$, and its color is $col_i$, where $col_i \in \{0, 1\}$.

Alice and Bob play a game on this tree. They take turns making moves, with Alice going first. In each turn, a player chooses a node $x$ such that $x=1$ or $p_x$ has already been removed, and removes $x$.

If the color of the last removed node is $0$, Alice wins; otherwise, Bob wins. Both players play optimally to win.

Given $T$ test cases, determine the winner for each case.

Input

The first line contains a positive integer $T$, representing the number of test cases. The format for each test case is as follows:

  • The first line contains a positive integer $n$.
  • The second line contains $n-1$ positive integers $p_2, p_3, \dots, p_n$.
  • The third line contains $n$ non-negative integers $col_1, col_2, \dots, col_n$.

Output

For each test case, output a single line containing Alice or Bob, indicating the winner.

Constraints

This problem uses subtask-based testing.

For all test cases, it is guaranteed that $1 \le T \le 10000$, $1 \le \sum n \le 5 \times 10^5$, $1 \le p_i < i$, and $0 \le col_i \le 1$.

Subtask $1$ ($20$ pts): Guaranteed $T=1, n \le 20$.

Subtask $2$ ($30$ pts): Guaranteed that for all $i$, $i=1 \lor p_i=1 \lor p_{p_i}=1$.

Subtask $3$ ($20$ pts): Guaranteed that for all $i$, either $i$ is a leaf or the size of the subtree rooted at $i$ is even.

Subtask $4$ ($30$ pts): No additional restrictions.

Examples

Input 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

Output 1

Alice
Bob
Alice

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.