QOJ.ac

QOJ

実行時間制限: 2 s メモリ制限: 4096 MB 満点: 100

#2287. 哈密顿徒步旅行

統計

Alice 喜欢徒步旅行。她经常背着背包,在森林和山脉中旅行数日。明年夏天,她决定去一个美丽的地区旅行,那里有许多小屋:徒步旅行者可以在那里放下睡袋过夜。这些小屋由徒步小径连接,小径沿着该地区的风景延伸,通向下一个小屋。

Alice 的计划是进行一次多日徒步旅行。每天,她都会沿着小径走到一个新的小屋过夜。她每天最多可以走三条小径——走四条小径太累了。为了尽可能多地体验这些小屋,Alice 决定她想在每个小屋至少住一晚。然而,夏天的时间有限:她没有时间多次访问同一个小屋。

Alice 注意到这需要仔细规划她的徒步路线,并想知道如何找到这样一条路线。请确定 Alice 每天应该走到哪个小屋。图 H.1 展示了第二个样例的一种可能路线。

输入格式

输入包含:

  • 一行包含两个整数 $n$ ($2 \le n \le 2 \cdot 10^5$) 和 $m$ ($1 \le m \le 2 \cdot 10^5$),分别表示小屋的数量和徒步小径的数量。
  • $m$ 行,每行包含两个整数 $x, y$ ($1 \le x, y \le n, x \neq y$),表示小屋 $x$ 和 $y$ 之间有一条徒步小径。

保证每个小屋都可以从其他任何小屋到达。任意两个小屋之间最多只有一条徒步小径。

输出格式

输出 Alice 应该访问 $n$ 个小屋的顺序。

你不需要最小化徒步小径的总数。

如果存在多个有效的解决方案,你可以输出其中任意一个。

图 H.1:第二个样例的输入和一条可能的路线(红色虚线箭头)。

样例

输入 1

4 3
1 2
1 3
1 4

输出 1

2 1 3 4

输入 2

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

输出 2

1 4 2 5 7 6 3

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

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.