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

33797번 - Pointers 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 2048 MB194110.000%

문제

You are given a connected undirected graph with $n$ nodes and $m$ edges. Each node $u$ has an ordered list $l_u$ of its neighbors, and an arrow pointing to one of its neighbors $p_u$. Initially, $p_u$ is the first neighbor in $l_u$.

You start at node $s,ドル and repeat the following process infinitely many times:

  1. Let $v$ be the node at which you are currently located. Move from $v$ to $p_v$.
  2. Increment $p_v$ to the next neighbor in $l_v$ cyclically.

See the sample notes for an example of this process.

Consider the list $p_1, p_2, \cdots p_n$ over the course of this process, as well as the current node $c$. We call this a "state".

Print any state that appears an infinite amount of times.

입력

The first line of the input 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 three integers $n,ドル $m,ドル and $k$ (1ドル \le n \le 2 \cdot 10^5,ドル $n - 1 \le m \le 4 \cdot 10^5,ドル 1ドル \le s \le n$) --- the number of vertices and edges in the graph, and the starting node, respectively.

The $u$-th of the next $n$ lines describes the ordered list $l_u$ of neighbors of $u$. It begins with an integer $k_u$ (1ドル \le k_u < n$) --- the number of neighbors of $u$. This is followed by $k_u$ distinct integers $v_1, v_2, \cdots v_{k_u}$ (1ドル \le v_i \le n,ドル $v_i \ne u$) --- the neighbors of $u$.

It is guaranteed that if $v$ is a neighbor of $u,ドル then $u$ is a neighbor of $v$. It is also guaranteed that there are $m$ undirected edges in total.

Across all test cases, it is guaranteed that the sum of $n$ is at most 2ドル \cdot 10^5,ドル and the sum of $m$ is at most 4ドル \cdot 10^5$.

출력

For each test case print any state that repeats infinitely in the format $c$ $p_1$ $p_2$ $...$ $p_n$.

제한

예제 입력 1

3
4 3 2
1 4
1 3
2 4 2
2 3 1
4 3 3
1 4
1 3
2 4 2
2 3 1
4 4 1
2 4 2
2 1 3
2 2 4
2 3 1

예제 출력 1

3 4 3 2 1
3 4 3 2 1
1 4 1 2 3

노트

Let's visualize the third sample case. The red node represents your current position, and the arrow pointing out from each node $u$ points at node $p_u$. Here is how the graph looks at the start of the process, and after each of the next 8ドル$ steps:

We can see that after 8ドル$ operations have been performed, we have reached the initial state $p_1 = 4, p_2 = 1, p_3 = 2, p_4 = 3$ once again, and our current location (node 1ドル$) is the same as it was at the beginning. Therefore, a valid answer is to simply print the initial state.

출처

University > Rutgers University > Rutgers University Programming Contest Spring 2025 K번

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

출처

대학교 대회

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

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