#K67142. Seating Arrangement for Students
Seating Arrangement for Students
Seating Arrangement for Students
You are given a classroom with n students numbered from 1 to n and m constraints. Each constraint is a pair of students (u, v) who must be seated next to each other. Your task is to determine if it is possible to arrange the students in a single row such that every given constraint is satisfied. In mathematical terms, for every constraint ( (u, v) ), the absolute difference between the positions of u and v in the seating arrangement must be exactly 1. If such an arrangement exists, output the arrangement as a sequence of space-separated integers; otherwise, output IMPOSSIBLE
.
The input is given in the following format:
- The first line contains two integers \( n \) and \( m \): the number of students and the number of constraints, respectively.
- The next \( m \) lines each contain two integers representing a constraint.
If ( m = 0 ), simply output the natural order from 1 to n.
inputFormat
The first line contains two integers ( n ) and ( m ) (1 ( \leq n \leq 10^5 ), 0 ( \leq m \leq 10^5 )). In the next ( m ) lines, each line contains two integers ( u ) and ( v ) representing the constraint that students u and v must be seated consecutively.
outputFormat
Output a single line containing the seating arrangement as a sequence of ( n ) space-separated integers if a valid arrangement exists. Otherwise, output IMPOSSIBLE
.## sample
4 3
1 2
2 3
3 4
1 2 3 4
</p>