QOJ.ac

QOJ

時間限制: 6 s 記憶體限制: 2048 MB 總分: 100

#9055. 古怪的远足

统计

Eddy 正在计划一次横跨 $n$ 个不同城市的旅行。这些城市之间由 $n-1$ 条道路连接。每条道路连接两个城市,且是双向的。这些道路的布局保证了仅通过道路即可在任意两个城市之间往来。

Eddy 想要规划一次旅行,使得他恰好访问每个城市一次。他可以从任意城市出发,并在任意城市结束。仅通过道路可能无法做到恰好访问每个城市一次。幸运的是,Eddy 可以在任意两个没有直接道路连接的城市之间乘坐航班。Eddy 希望在旅行中恰好乘坐 $k$ 次航班。

请帮助 Eddy 规划他的行程。

输入格式

第一行包含两个整数 $n, k$ ($0 \le k < n \le 500$),其中 $n$ 是 Eddy 要访问的城市数量,$k$ 是 Eddy 希望乘坐的航班次数。

接下来的 $n-1$ 行,每行包含两个整数 $a, b$ ($1 \le a < b \le n$),表示城市 $a$ 和城市 $b$ 之间有一条道路。保证仅通过道路即可在任意两个城市之间往来。

输出格式

输出 $n$ 个整数,指定 Eddy 按顺序访问的城市序列。该序列必须恰好访问每个城市一次,且恰好使用 $k$ 次航班。如果存在多种可能的行程,输出字典序最小的序列。如果不存在可能的行程,输出 $-1$。

样例

样例输入 1

4 1
1 2
1 3
1 4

样例输出 1

2 1 3 4

样例输入 2

4 0
1 2
1 3
1 4

样例输出 2

-1

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.