Mosaic Tracery

면접 대비

시간 제한2초메모리 제한1024 MB

요약
번호가 뒤섞인 격자 그래프가 주어질 때 각 정점에 정수 좌표를 부여해 모든 간선이 격자에서 이웃하도록 만든다.
난이도

보통10점 중 6점

유형
그래프, BFS, 구현
정답자
아직 제출이 없습니다

문제

One of the squares of the town in far-away Oriental country is art mosaic panel consisting of multicolored tiles. The most attractive square feature for tourists is that sometimes some set of tiles is extracted from the mosaic panel and replaced by tiles of another color, thus the mosaic tracery has changed.

Square surface is modelled by the peace of square plane and every tile is the square with side of length one on the plane. Mosaic piece that is planned to output is defined by following algorithm. At the first is marked any tile, then any another that have common side with the first, then any from residual tiles that have common side with one of the already taken tiles and so on. Becouse the painter entrusted with new picture drawing lives in other town the tile desription had been writed before outputting them. All points of square grid that are the corners of at least one of the extracting multicolored tiles were numbered from 11 to NN. After that the sequence of all pairs of neighbour points, that is either their xx-coordinates are equal and the absolute value of difference of yy-coordinates is one or their yy-coordinates are equal and the absolute value of difference of xx-coordinates is one, had been writed.

However before that description have been got to the painter it was been fallen into hands of mathematicians. As a result of their interest for various graph transformations the points turned out renumbered in chaotic order although their numbers are still different numbers from 11 to NN and pair of points in sequence are neighbours.

Thus is needed program for painter that reconstructs from this description initial coordinates of mosaic corners. With all this going on may be multiple variants but program may output any of possible variants becouse rotation or reflection is not a problem for painter.

입력

The first line of input contains two integers NN and MM: the number of numbered points and the number of pairs of neighbour points (4≤N≤100,0004 \le N \le 100\\,000). Each of next following lines contains two integers U_iU\_{i} and V_iV\_{i}: numbers of neighbour points (1≤U_i,V_i≤N1 \le U\_{i}, V\_{i} \le N, 1≤i≤M1 \le i \le M). It is guaranteed that answer exists.

출력

Output NN lines containing two integers X_jX\_{j} and Y_jY\_{j}: coordinates of point number jj (−105≤X_j,Y_j≤105- 10^5 \le X\_{j}, Y\_{j} \le 10^5, 1≤j≤N1 \le j\le N). Set of points with integer coordinates may be answer for painter if all points have different coordinates and for any pair (U_i,V_i)(U\_{i}, V\_{i}) coordinates of points U_iU\_{i} and V_iV\_{i} are neighbour on square plane.

예제2

  1. 예제 1

    입력
    8 10
    1 4
    3 4
    6 7
    2 8
    2 7
    5 3
    5 6
    1 7
    1 5
    1 8
    
    예상 출력
    1 1
    0 0
    2 2
    2 1
    1 2
    0 2
    0 1
    1 0
    
  2. 예제 2

    입력
    26 39
    7 10
    25 17
    12 14
    10 2
    9 15
    4 7
    1 3
    23 13
    19 14
    11 26
    15 13
    26 20
    18 17
    16 6
    7 12
    9 11
    21 18
    3 18
    13 20
    22 23
    6 24
    1 21
    16 8
    5 12
    22 15
    19 1
    25 9
    24 9
    3 25
    15 26
    17 11
    12 16
    2 6
    10 16
    4 5
    8 25
    14 3
    5 19
    8 24
    
    예상 출력
    3 3
    0 0
    2 3
    3 0
    3 1
    0 1
    2 0
    1 2
    0 3
    1 0
    0 4
    2 1
    -2 3
    2 2
    -1 3
    1 1
    1 4
    2 4
    3 2
    -2 4
    3 4
    -1 2
    -2 2
    0 2
    1 3
    -1 4