Logo
(追記) (追記ここまで)

21825번 - Through Another Maze Darkly 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
8 초 512 MB48262251.163%

문제

There is a maze that is formed by connecting N rooms via N − 1 corridors. The rooms are numbered 1 to N and each room has the shape of a circle. The corridors have the following constraints:

  • Each corridor forms a connection between two distinct rooms.
  • Every pair of rooms is connected by exactly one path of connected corridors.

One difficulty in navigating through this maze is that the lights are all out, so you cannot see where you are. To help with navigation, each room contains a laser pointer that initially points to a corridor. Consider the following strategy:

  • Rotate the room’s laser pointer clockwise until it points to another corridor.
  • Follow the room’s laser pointer and traverse the corridor.
  • Repeat the previous two steps indefinitely.

You created Q queries to investigate this strategy. For each query, you are given an integer K and you start at room 1. Determine the final room after traversing exactly K corridors. All laser pointers will reset to their original orientation after each query.

입력

The first line contains the integers N and Q (2 ≤ N ≤ 800 000, 1 ≤ Q ≤ 800 000).

The next N lines describe the layout of the maze, with the ith of these lines describing room i. Specifically, it contains an integer k, the number of corridors connecting to room i, followed by k integers, c1 c2 . . . ck, indicating the rooms that these k corridors lead to, in clockwise order. Lastly, room i’s laser pointer initially points to the corridor leading to room c1.

The final Q lines describe a query, with each line containing an integer K (1 ≤ K ≤ 1015).

출력

Output Q lines answering the queries in order.

제한

예제 입력 1

5 6
1 2
3 3 1 4
1 2
2 5 2
1 4
1
2
3
4
5
6

예제 출력 1

2
1
2
4
2
3

힌트

This is the initial state of the maze.

The strategy will visit these rooms in order:

1, 2, 1, 2, 4, 2, 3, . . .

출처

Olympiad > Canadian Computing Competition & Olympiad > 2021 > CCO 2021 3번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /