ALICEBOB - Alice and Bob

This is a puzzle for two persons, let's say Alice and Bob. Alice draws an n-vertex convex polygon and numbers its vertices with integers 1, 2, ... , n in an arbitrary way. Then she draws a number of noncrossing diagonals (the vertices of the polygon are not considered to be crossing points). She informs Bob about the sides and the diagonals of the polygon but not telling him which are which. Each side and diagonal is specified by its ends. Bob has to guess the order of the vertices on the border of the polygon. Help him solve the puzzle.

If n = 4 and (1,3), (4,2), (1,2), (4,1), (2,3) are the ends of four sides and one diagonal then the order of the vertices on the border of this polygon is 1, 3, 2, 4 (with the accuracy to shifting and reversing).

Task

Write a program that:

  • reads the description of sides and diagonals given to Bob by Alice,
  • computes the order of the vertices on the border of the polygon,
  • writes the result.

Input

The first line of the input contains exactly one positive integer d equal to the number of data sets, 1 <= d <= 20. The data sets follow.

Each data set consists of exactly two consecutive lines.

The first of those lines contains exactly two integers n and m separated by a single space, 3 <= n <= 10 000, 0 <= m <= n-3. Integer n is the number of vertices of a polygon and integer m is the number of its diagonals, respectively.

The second of those lines contains exactly 2(m+n) integers separated by single spaces. Those are ends of all sides and some diagonals of the polygon. Integers aj, bj on positions 2j-1 and 2j, 1 <= j < = m+n, 1 < = aj <= n, 1 < = bj < = n, aj <> bj, specify ends of a side or a diagonal. The sides and the diagonals can be given in an arbitrary order. There are no duplicates. Alice does not cheat, i.e. the puzzle always has a solution.

Output

Line i, 1 <= i < = d, should contain a sequence of n integers separated by single spaces - a permutation of 1, 2, ... , n, i.e. the numbers of subsequent vertices on the border of the polygon from the i-th data set, the sequence should always start from 1 and its second element should be the smaller vertex of the two border neighbours of vertex 1.

Example

Sample input:
1 
4 1 
1 3 4 2 1 2 
4 1 2 3 

Sample output:
1 3 2 4 
Warning: large Input/Output data, be careful with certain languages

Added by:adrian
Date:2004-07-02
Time limit:7s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All
Resource:ACM Central European Programming Contest, Warsaw 2001

hide comments
2024-07-16 10:32:45
Error 1 error C2144: syntax error : 'void' should be preceded by ';' c:\program files (x86)\windows kits\8.0\include\um\gl\gl.h 1157 1 game_gr9_1507
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\program files (x86)\windows kits\8.0\include\um\gl\gl.h 1157 1 game_gr9_1507
Error 3 error C2146: syntax error : missing ';' before identifier 'glAccum' c:\program files (x86)\windows kits\8.0\include\um\gl\gl.h 1157 1 game_gr9_1507
Error 4 error C2182: 'APIENTRY' : illegal use of type 'void' c:\program files (x86)\windows kits\8.0\include\um\gl\gl.h 1157 1 game_gr9_1507
Error 5 error C2144: syntax error : 'void' should be preceded by ';' c:\program files (x86)\windows kits\8.0\include\um\gl\gl.h 1158 1 game_gr9_1507
Error 6 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\program files (x86)\windows kits\8.0\include\um\gl\gl.h 1158 1 game_gr9_1507
<snip>
[Simes]: that's enough, we don't need to see another 219 lines of this. Is this related to the problem ALICEBOB somehow? Is seems like you might be trying to include a Windows OpenGL header from a Linux server.


Last edit: 2024-07-17 15:11:06
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.