#P11832. Lexicographically Smallest Permutation Restoration

    ID: 13932 Type: Default 1000ms 256MiB

Lexicographically Smallest Permutation Restoration

Lexicographically Smallest Permutation Restoration

Let (n) and (m) be two positive integers. You are given an undirected graph (G=(V,E)) with vertices (V={1,2,\ldots,n}) and exactly (m) edges. It is known that there exists a collection of (m) distinct pairs of positive integers ({(a_i,b_i)}_{i=1}^m) satisfying the conditions

[ 1 \le a_i < b_i \le n, \quad \text{for } i=1,2,\ldots,m, ]

and

[ \text{there do not exist } 1 \le i,j \le m \text{ such that } a_i < a_j < b_i < b_j. ]

A friend has a permutation (p = [p_1,p_2,\ldots,p_n]) of ({1,2,\ldots,n}). Using the above pairs and the permutation (p), the graph (G) is constructed by taking

[ E = { (p_{a_i}, p_{b_i}) \mid 1 \le i \le m }. ]

Note that for each edge ((u,v)) (where (u) and (v) are the endpoints in (G)), if we let (u' = \min(u,v)) and (v' = \max(u,v)), then in order for (p) to be consistent with some valid collection of pairs ({(a_i,b_i)}), it must be that (u') appears before (v') in (p). In other words, for every edge ((u,v)), the smaller of the two numbers must appear earlier than the larger number in (p).

Your task is to find the lexicographically smallest permutation (p) that may have been used to construct (G) under the assumption that a valid collection of pairs ({(a_i,b_i)}) (satisfying the non crossing condition) exists. It can be shown that under these conditions, the lexicographically smallest (p) is the identity permutation ([1, 2, \ldots, n]).


Input Format: The first line contains two integers (n) and (m) --- the number of vertices and the number of edges, respectively.

Then follow (m) lines, each containing two integers (u) and (v) representing an edge in (G). Note that the order of (u) and (v) is arbitrary. For each edge, by letting (u' = \min(u,v)) and (v' = \max(u,v)), the permutation (p) must satisfy that (u') appears before (v').


Output Format: Output the lexicographically smallest permutation (p) of ({1,2,\ldots,n}) that satisfies the above condition. Since it can be proved that the identity permutation ([1,2,\ldots,n]) is always a valid answer, simply output these numbers separated by a space.

inputFormat

The first line contains two integers (n) and (m) ((1 \le n \le 10^5), (0 \le m \le n-1)). Each of the following (m) lines contains two integers (u) and (v) ((1 \le u,v \le n)), representing an edge of the graph. It is guaranteed that there exists at least one permutation that can produce (G) using some set of non crossing pairs.

outputFormat

Output a single line containing (n) integers --- the lexicographically smallest permutation (p) that can be obtained. (Print the numbers separated by a single space.)

sample

4 1
2 3
1 2 3 4

</p>