You Are a Robot
There is a track system consisting of intersections, numbered from to . The track forms a tree rooted at intersection . An unstoppable trolley starts at intersection 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.
Input
Each test contains multiple test cases. The first line contains a single integer () — the number of test cases. The description of the test cases follows.
The first line of each test case contains an integer () — the number of intersections.
The second line of each test case contains integers (), where denotes the parent of intersection in the tree.
The third line of each test case contains integers (), where describes the type of the track segment between node and node :
- denotes an empty segment,
- denotes a human,
- denotes a robot.
The sum of over all test cases does not exceed .
Output
For each test case, output a single integer denoting a possible answer. If there are multiple possible answers, you may output any.
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
4 4 4
Discussions & Comments
Share your approach or ask questions about this problem (0)
You must be logged in to comment or start a discussion on this problem.
Log InNo comments yet. Be the first to comment!
Actions
Open on CodeforcesAbout Platform
Problem Discussions
0Have questions or want to share your solution approach? Join the discussion.
View / write comments