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

21991번 - Guide 스페셜 저지다국어

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

문제

Mister Gooti is the world-famous guide of The Freezing Isles. The topology of the Isles can be represented as a tree with cities at the vertices and two-way roads between them. Gooti prepares a new sightseeing tour over the Isles. He wants to find the shortest path that starts in the capital and visits $k$ different cities, including the capital. Please, help him.

입력

The first line of the input contains the number of tests $T$ (1ドル \leq T \leq 100$). Each test consists of two lines. The first line contains the overall number of cities $n$ in the Isles and the requested number of cities $k$ for the tour (1ドル \leq k \leq n \leq 100$). The second line contains the description of the tree in a rooted manner: $n - 1$ integers where the $i$-th integer, $p_i,ドル is the parent of the city $i + 1$ (1ドル \leq p_i \leq i$). The capital is the city with the number 1ドル$ --- the root of the tree.

출력

For each test, the first line of the output shall contain the length of the path $l$. The second line shall contain $l + 1$ integers --- the cities that lie on the path in the order of the traversal.

제한

예제 입력 1

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

예제 출력 1

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

노트

The following pictures illustrate all the three tests from the example.

출처

ICPC > Regionals > Northern Eurasia > Northern Eurasia Finals > Northern Eurasia Finals 2020 (Offline) G번

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

출처

대학교 대회

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

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