QOJ.ac

QOJ

حد الوقت: 2 s حد الذاكرة: 1024 MB مجموع النقاط: 100

#14862. 思乡

الإحصائيات

今天是公元前 225 年 8 月 25 日。你负责组织罗马“反折返漫步者俱乐部”的年度公路旅行。唉,你很容易想家,宁愿呆在家里。因此,你的目标是让这次公路旅行的路线尽可能短。根据传统,旅行中不能沿着刚刚走过的道路折返——否则你的朋友们会开始抱怨。具体来说,如果你直接从地点 $x$ 旅行到地点 $y$,你不能立即沿着同一条路从 $y$ 返回到 $x$。

图 H.1:样例输入 2。该图展示了一个使用六条道路的有效行程。连接地点 1 和 4 的道路被使用了两次。

给你一个可能访问的地点列表以及连接它们的道路。请找出一条能让你的朋友们开心且长度最短的公路旅行路线。

这次公路旅行必须从你的家(地点 1)开始,并且必须访问至少一个其他地点(最后回到地点 1)。

输入格式

输入包含以下内容:

  • 第一行包含两个整数 $n$ 和 $m$($2 \le n \le 10^5$,$1 \le m \le 2 \cdot 10^5$),分别表示地点的数量和道路的数量。
  • 接下来的 $m$ 行,每行包含两个整数 $u$ 和 $v$($1 \le u < v \le n$),表示地点 $u$ 和 $v$ 之间有一条道路。道路可以双向通行。每对地点之间最多只有一条道路直接相连。

输出格式

如果无法进行这样的公路旅行,输出 impossible

否则,输出你计划的公路旅行路线:首先输出一个整数 $k$,表示旅行中访问的地点数量(包括起点和终点处的家,即家会被计算两次),然后依次输出这 $k$ 个地点,表示访问它们的顺序。

如果存在多个满足要求的解,你可以输出其中任意一个。

样例

输入样例 1

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

输出样例 1

4
1 3 2 1

输入样例 2

12 13
1 2
2 3
1 4
4 5
5 6
6 7
4 7
1 8
8 9
9 10
10 11
11 12
9 12

输出样例 2

7
1 4 5 6 7 4 1

输入样例 3

3 2
1 2
2 3

输出样例 3

impossible

输入样例 4

4 3
2 3
3 4
2 4

输出样例 4

impossible

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.