luogu#P7830. [CCO 2021] Through Another Maze Darkly
[CCO 2021] Through Another Maze Darkly
Background
Warning: abusing the judging system for this problem will result in an account ban!
Problem Description
The Dark Maze is a tree structure with rooms and corridors. The rooms are numbered .
The Dark Maze is completely dark, so you cannot see where you are. To tell directions, each room has a laser pointer, which initially points to one of the corridors connected to that room. You repeatedly follow the strategy below:
- Rotate the laser pointer in the current room clockwise to the next corridor.
- Walk along the corridor pointed to by the laser pointer to the other room.
You plan to start from room and repeat this strategy times, and you want to know which room you will end up in. You think this problem is too easy, so you make queries. Each query is independent, meaning that for each query all laser pointers return to their initial states.
Input Format
The first line contains two integers .
The next lines describe the rooms. Line describes room . First, an integer indicates the number of corridors connected to room . Then integers are given, indicating, in clockwise order, the room number at the other end of each corridor. The laser pointer in room initially points to the corridor leading to room .
The next lines each contain one positive integer .
Output Format
For each query, output one line containing the required value.
5 6
1 2
3 3 1 4
1 2
2 5 2
1 4
1
2
3
4
5
6
2
1
2
4
2
3
Hint
Sample #1 Explanation
The initial directions of the laser pointers are shown in the figure:

Constraints
For of the testdata, room is connected to rooms and (if those rooms exist).
For another of the testdata, , .
For another of the testdata, .
For of the testdata, , , . It is guaranteed that the given data forms a tree.
Source
CCO2021 D1T3
Translated by ChatGPT 5