Logo
(追記) (追記ここまで)

26032번 - Icy Itinerary 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 (추가 시간 없음) 1024 MB120353328.696%

문제

It is a harsh and cold winter, in a town consisting of $n$ houses. Everybody is asleep in the early morning hours. The snow lies deep on the ground, except on the $m$ roads that connect some pairs of houses. Only Thomas is awake.

Thomas the mailman needs to deliver mail to each of the $n$ houses in the town. The houses are numbered from 1ドル$ to $n$. Thomas will start in his own house (house 1ドル$), and then visit all the other houses in some order. He can use a bicycle to get between two houses connected by a road, and he can use skis if there is no road between the houses. But it is not possible to use skis on roads and the bicycle outside of roads. Switching between bicycle and skis is tedious, so Thomas would like to do this at most once.

Your task is to find an ordering $a_1, a_2, \cdots, a_n$ of the $n$ houses so that $a_1 = 1,ドル and there is at most one index $i$ (2ドル \leq i \leq n-1$) such that either

  1. $a_{i-1}$ and $a_i$ are connected by a road, but $a_i$ and $a_{i+1}$ are not, or
  2. $a_{i-1}$ and $a_i$ are not connected by a road, but $a_i$ and $a_{i+1}$ are.

In other words, the sequence starts at 1ドル$ and switches between using roads and non-roads at most once.

입력

The first line contains two integers $n,ドル $m$ (2ドル \leq n \leq 3 \cdot 10^5,ドル 0ドル \leq m \leq 3 \cdot 10^5$), the number of houses and the number of roads.

The next $m$ lines each contain two integers $u_i, v_i$ (1ドル \leq u_i \neq v_i \leq n$), meaning that $u_i$ and $v_i$ are connected by a road. The roads can be used in both directions, and all the unordered pairs $\{u_i, v_i\}$ are distinct.

There exists a valid ordering for every case in the input.

출력

Print $n$ integers $a_1, a_2, \cdots, a_n$ on one line, the order in which to visit the houses.

Remember that the first number $a_1$ should be 1ドル$.

제한

예제 입력 1

4 4
1 2
1 3
1 4
3 4

예제 출력 1

1 4 3 2

예제 입력 2

5 0

예제 출력 2

1 2 3 4 5

힌트

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > Nordic Collegiate Programming Contest > NCPC 2022 I번

  • 문제를 만든 사람: Johan Sannemo, Nils Gustafsson
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /