#jag2017summerday3c. [jag2017summer_day3_c]Ninja Map
[jag2017summer_day3_c]Ninja Map
MathJax.Hub.Config({ tex2jax: { inlineMath: [[""], ["\\(","\\)"]], processEscapes: true }}); blockquote { font-family: Menlo, Monaco, "Courier New", monospace; color: #333333; display: block; padding: 8.5px; margin: 0 0 9px; font-size: 16px; line-height: 18px; background-color: #f5f5f5; border: 1px solid #ccc; border: 1px solid rgba(0, 0, 0, 0.15); -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; white-space: pre; white-space: pre-wrap; word-break: break-all; word-wrap: break-word; }
Problem Statement
Intersections of Crossing Path City are aligned to a grid. There are east-west streets which are numbered from 1 to , from north to south. There are also north-south streets which are numbered from 1 to , from west to east. Every pair of east-west and north-south streets has an intersection; therefore there are intersections which are numbered from 1 to .
Surprisingly, all of the residents in the city are Ninja. To prevent outsiders from knowing their locations, the numbering of intersections is shuffled.
You know the connections between the intersections and try to deduce their positions from the information. If there are more than one possible set of positions, you can output any of them.
Input
The input consists of a single test case formatted as follows.
The first line consists of an integer . The following lines represent connections between intersections. The -th line consists of two integers and (, ), which represent that the -th and -th intersections are adjacent. More precisely, let's denote by the intersection of the -th east-west street and the -th north-south street. If the intersection number of is for some and , then the intersection number of either , , or must be . All inputs of adjacencies are different, i.e., and for all . This means that you are given information of all adjacencies on the grid.
The input is guaranteed to describe a valid map.
Output
Print a possible set of positions of the intersections. More precisely, the output consists of lines each of which has space-separated integers. The -th integer of the -th line should be the intersection number of .
If there are more than one possible set of positions, you can output any of them.
Sample Input 1
3
1 2
4 7
8 6
2 3
8 9
5 3
4 6
5 6
7 8
1 4
2 6
5 9
Output for Sample Input 1
7 4 1
8 6 2
9 5 3
The following output will also be accepted.
1 2 3
4 6 5
7 8 9
Sample Input 2
4
12 1
3 8
10 7
13 14
8 2
9 12
6 14
11 3
3 13
1 10
11 15
4 15
4 9
14 10
5 7
2 5
6 1
14 5
16 11
15 6
15 13
9 6
16 4
13 2
Output for Sample Input 2
8 2 5 7
3 13 14 10
11 15 6 1
16 4 9 12