Ninja Map
시간 제한2초메모리 제한512 MB
노드 번호가 뒤섞인 N x N 격자 그래프의 모든 인접 관계가 주어질 때, 번호를 격자에 배치하는 한 가지 방법을 복원한다.
문제
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.
입력
The input consists of a single test case formatted as follows.
$N$ $a_1 \ b_1$ $\cdots$ $a_{2N^2-2N} \ b_{2N^2-2N}$
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.
출력
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.