156. Strange Graph¶
time limit per test: 0.25 sec / memory limit per test: 4096 KB
Input
The first line of the input file contains two integer numbers N and M - the number of vertices and edges in G respectively (3 <= N <= 10000, M <= 100000). 2M integer numbers follow - each pair represents vertices connected by the corresponding edge (vertices are numbered from 1 to N). It is guaranteed that each edge occurs exactly once in the input file and that there are no loops (i.e. ends of each edge are distinct).
Output
If there is no hamiltonian cycle in G, print -1 in the first line of the output file. In the other case output N numbers - the sequence of vertices of G as they appear in the hamiltonian cycle found (note that the last vertex must be connected to the first one). If there are several solutions, output any one.
Example(s)
| Sample Input | Sample Output |
4 4
1 2 2 3 3 4 4 1
|
1 2 3 4
|
| Sample Input | Sample Output |
9 12
1 2 2 3 3 1 1 4 2 5 3 6
4 7 5 8 6 9 7 8 8 9 9 7
|
-1
|