PivotOJ

Homesick

시간 제한: 2000ms메모리 제한: 2048MB출처: BAPC 2025BOJ 35211

문제

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 xx to site yy, you cannot immediately go back from yy to xx 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 11, your home, and must visit at least one other site.

입력

The input consists of:

  • One line with two integers nn and mm (\(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 uu and vv (\(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 kk, the number of sites to visit on the road trip (including your home twice), followed by the kk 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
출력
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
출력
7
1 4 5 6 7 4 1

예제 3

입력
3 2
1 2
2 3
출력
impossible

예제 4

입력
4 3
2 3
3 4
2 4
출력
impossible
이 문제는 채점 준비 중입니다. 테스트 데이터가 확보되면 제출이 가능합니다.