QOJ.ac

QOJ

时间限制: 3 s 内存限制: 512 MB 总分: 100

#1668. 指南

统计

Mister Gooti 是冰封群岛(The Freezing Isles)世界闻名的向导。群岛的拓扑结构可以表示为一棵树,城市位于顶点,双向道路连接它们。Gooti 正在筹划一次新的群岛观光之旅。他想要找到一条从首都出发,并访问 $k$ 个不同城市(包括首都)的最短路径。请帮助他。

输入格式

输入的第一行包含测试用例的数量 $T$ ($1 \le T \le 100$)。每个测试用例包含两行。 第一行包含群岛中城市的总数 $n$ 以及观光之旅要求的城市数量 $k$ ($1 \le k \le n \le 100$)。 第二行以有根树的方式描述了这棵树:包含 $n-1$ 个整数,其中第 $i$ 个整数 $p_i$ 是城市 $i+1$ 的父节点 ($1 \le p_i \le i$)。首都为编号为 $1$ 的城市,即树的根节点。

输出格式

对于每个测试用例,第一行应包含路径的长度 $l$。第二行应包含 $l+1$ 个整数,即按遍历顺序排列的路径上的城市。

样例

样例输入 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

说明

下图展示了样例中的所有三个测试用例。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.