Under construction

Still being built. Things may change

Icy Itinerary

Time limit3sMemory limit1024 MB

Summary
Find an order of all n houses starting at house 1 where road moves and non-road moves switch at most once.
Level

Medium7 of 10

Topics
Graph, BFS, Greedy
Solved
No attempts yet

Problem

It is a harsh, cold winter in a town of nn houses, and everyone is asleep in the early morning. Snow lies deep on the ground except on the mm roads that connect some pairs of houses. Only Thomas is awake.

Thomas the mailman has to deliver mail to each of the nn houses. The houses are numbered from 1 to nn. He starts at his own house (house 1) and then visits all the other houses in some order. He can ride a bicycle between two houses connected by a road, and he can use skis between two houses with no road between them. Skis cannot be used on roads, and the bicycle cannot be used off roads. Switching between bicycle and skis is tedious, so he wants to switch at most once.

Find an ordering a1,a2,⋯ ,ana_1, a_2, \cdots, a_n of the houses with a1=1a_1 = 1 such that there is at most one index ii (2≤i≤n−12 \leq i \leq n-1) where either

  1. ai−1a_{i-1} and aia_i are connected by a road, but aia_i and ai+1a_{i+1} are not, or
  2. ai−1a_{i-1} and aia_i are not connected by a road, but aia_i and ai+1a_{i+1} are.

In other words, the sequence starts at 1 and switches between road and non-road moves at most once.

Input

The first line contains two integers nn and mm (2≤n≤3⋅1052 \leq n \leq 3 \cdot 10^5, 0≤m≤3⋅1050 \leq m \leq 3 \cdot 10^5), the number of houses and the number of roads.

Each of the next mm lines contains two integers uiu_i and viv_i (1≤ui≠vi≤n1 \leq u_i \neq v_i \leq n), meaning that uiu_i and viv_i are connected by a road. Roads can be used in both directions, and all unordered pairs {ui,vi}\{u_i, v_i\} are distinct.

A valid ordering exists for every input.

Output

Print nn integers a1,a2,⋯ ,ana_1, a_2, \cdots, a_n on one line, the order in which to visit the houses. The first number a1a_1 must be 1.

Examples2

  1. Example 1

    Input
    4 4
    1 2
    1 3
    1 4
    3 4
    
    Expected output
    1 4 3 2
    
  2. Example 2

    Input
    5 0
    
    Expected output
    1 2 3 4 5