#P12906. [NERC 2020] Guide
[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 different cities, including the capital. Please, help him.
输入格式
The first line of the input contains the number of tests (). Each test consists of two lines. The first line contains the overall number of cities in the Isles and the requested number of cities for the tour (). The second line contains the description of the tree in a rooted manner: integers where the -th integer, , is the parent of the city (). The capital is the city with the number --- the root of the tree.
输出格式
For each test, the first line of the output shall contain the length of the path . The second line shall contain 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.