#P15000. [Nordic OI 2019] Graph Ordering

[Nordic OI 2019] Graph Ordering

题目描述

You are given an undirected connected graph that has nn nodes. The nodes are numbered 1,2,,n1, 2, \ldots, 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 aa to node bb, node aa is before node bb 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.

输入格式

The first line has two integers nn and mm: the number of nodes and edges.

After this, there are mm lines that describe the edges. Each line has two integers aa and bb: there is an edge between nodes aa and bb.

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

输出格式

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

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

提示

Subtask 1 (7 points)

  • 2n1052 \leq n \leq 10^5
  • The graph is a tree.

Subtask 2 (29 points)

  • 2n1002 \leq n \leq 100
  • 1m2001 \leq m \leq 200

Subtask 3 (18 points)

  • 2n20002 \leq n \leq 2000
  • 1m50001 \leq m \leq 5000

Subtask 4 (21 points)

  • 2n1052 \leq n \leq 10^5
  • 1m21051 \leq m \leq 2 \cdot 10^5
  • It is guaranteed that there exists a valid ordering with node 1 as the source, and node nn as the sink.

Subtask 5 (25 points)

  • 2n1052 \leq n \leq 10^5
  • 1m21051 \leq m \leq 2 \cdot 10^5