QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#15335. Graph Ordering

統計

You are given an undirected connected graph that has $n$ nodes. The nodes are numbered $1,2,\dots,n$.

Let us consider an ordering of the nodes. The first node in the ordering is called the source, and the last node is called the sink. In addition, a path is called valid if always when we move from node $a$ to node $b$, node $a$ is before node $b$ in the ordering.

Your task is to find an ordering such that (1) there is a valid path from the source to every node, and (2) there is a valid path from every node to the sink, or determine that it is not possible to create such an ordering.

Input

The first line has two integers $n$ and $m$: the number of nodes and edges.

After this, there are $m$ lines that describe the edges. Each line has two integers $a$ and $b$: there is an edge between nodes $a$ and $b$.

It is guaranteed that the graph is connected, contains no self-loops and there is at most one edge between every pair of nodes.

Output

Print any valid ordering of the nodes. If there are no solutions, print "IMPOSSIBLE".

Examples

Input 1

5 5
4 2
3 4
2 1
3 1
1 5

Output 1

4 2 3 1 5

Input 2

4 3
1 2
3 2
4 2

Output 2

IMPOSSIBLE

Subtasks

Subtask 1 (7 points)
  • $2 \le n \le 10^{5}$
  • The graph is a tree.

Subtask 2 (29 points)

  • $2 \le n \le 100$
  • $1 \le m \le 200$

Subtask 3 (18 points)

  • $2 \le n \le 2000$
  • $1 \le m \le 5000$

Subtask 4 (21 points)

  • $2 \le n \le 10^{5}$
  • $1 \le m \le 2 \cdot 10^{5}$
  • It is guaranteed that there exists a valid ordering with node $1$ as the source, and node $n$ as the sink.

Subtask 5 (25 points)

  • $2 \le n \le 10^{5}$
  • $1 \le m \le 2 \cdot 10^{5}$

Discussions

About Discussions

The discussion section is only for posting: Editorials, General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues. Submitting multiple issues may cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.