CF2214I.You Are a Robot
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There is a track system consisting of $ n $ intersections, numbered from $ 1 $ to $ n $ . The track forms a tree rooted at intersection $ 1 $ . An unstoppable trolley starts at intersection $ 1 $ and moves along the edges of the tree.
Each edge, corresponding to a track segment, contains one of the following:
- a human,
- a robot,
- nothing.
You are a robot, and all robots share a unified mind. You can control the direction of the trolley at any intersection it arrives at.
The trolley stops when there are no further directions it can take. Determine the intersection at which the trolley will stop.
If there are multiple possible answers, you may output any.
输入格式
Each test contains multiple test cases. The first line contains a single integer $ t $ ( $ 1 \le t \le 10^4 $ ) — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer $ n $ ( $ 1 \le n \le 2 \cdot 10^5 $ ) — the number of intersections.
The second line of each test case contains $ n - 1 $ integers $ p_2, p_3, \ldots, p_n $ ( $ 1 \le p_i \lt i $ ), where $ p_i $ denotes the parent of intersection $ i $ in the tree.
The third line of each test case contains $ n - 1 $ integers $ a_2, a_3, \ldots, a_n $ ( $ 0 \le a_i \le 2 $ ), where $ a_i $ describes the type of the track segment between node $ p_i $ and node $ i $ :
- $ 0 $ denotes an empty segment,
- $ 1 $ denotes a human,
- $ 2 $ denotes a robot.
The sum of $ n $ over all test cases does not exceed $ 2 \cdot 10^5 $ .
输出格式
For each test case, output a single integer denoting a possible answer. If there are multiple possible answers, you may output any.
输入输出样例
输入#1
3 4 1 2 3 0 1 2 5 1 1 2 3 0 1 2 2 5 1 1 2 2 0 1 2 1
输出#1
4 4 4
说明/提示
null
输入解题思路,AI测评打分。不知道怎么写?