#P12906. [NERC 2020] Guide

    ID: 12677 Type: RemoteJudge 3000ms 512MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>2020Special JudgeICPCNERC/NEERC

[NERC 2020] Guide

题目描述

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 kk different cities, including the capital. Please, help him.

输入格式

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

输出格式

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

3
6 2
1 1 2 2 3
6 6
1 1 2 2 3
6 4
1 2 3 4 5
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.