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 ,表示胜者。

样例输入

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

样例输出

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): 无特殊限制。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.