시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 2048 MB999100.000%

문제

It is the 25th of August, 225 BCE. You are in charge of the annual road trip of the Backtracking-Averse Promenaders Club in Rome. Alas, you get homesick easily and would much rather stay at home. Therefore, your goal is to keep the road trip as short as possible. Traditionally, the road trip cannot backtrack along a road it just used -- your friends would start to complain. Specifically, if you travel directly from site $x$ to site $y$, you cannot immediately go back from $y$ to $x$ along the same road.

Figure H.1: Sample Input 2. The illustration shows a valid trip using six roads. The road connecting sites 1 and 4 is used twice.

You are given a list of sites to possibly visit and the roads connecting them. Find the road trip with the shortest length that would keep your friends happy.

The road trip must start at site $1$, your home, and must visit at least one other site.

입력

The input consists of:

  • One line with two integers $n$ and $m$ (\(2\leq n\leq 10^{5}\), \(1\leq m\leq 2\cdot 10^{5}\)), the number of sites and the number of roads.
  • \(m\) lines, each with two integers $u$ and $v$ (\(1\leq u < v \leq n\)), indicating there is a road between sites \(u\) and \(v\). Roads can be travelled in either direction. Each pair of sites is connected by at most one road.

출력

If there is no road trip possible, output "impossible". Otherwise, output a your planned road trip, described by an integer $k$, the number of sites to visit on the road trip (including your home twice), followed by the $k$ sites, in the order of visiting them.

If there are multiple valid solutions, you may output any one of them.

예제 입력 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

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > Benelux Algorithm Programming Contest > BAPC 2025 H번

  • 문제를 만든 사람: Jonas van der Schaaf