Puzzle

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

요약
각 조각은 H개의 구간이 쌓인 형태이며, 모든 조각을 나란히 놓아 하나의 직사각형을 만드는 순서를 찾는다.
난이도

보통10점 중 5점

유형
정렬, 구현
정답자
아직 제출이 없습니다

문제

Zigmas has a rectangular jigsaw puzzle of height HH and width WW. The puzzle consists of NN pieces. Each piece is constructed from HH rectangles of unit height stacked on one another. The pieces are shuffled, but neither rotated nor flipped.

Help Zigmas solve the puzzle by writing down how to order the pieces to get a perfect rectangle. The pieces can't be rotated or flipped, they can't overlap and there must be no gaps left.

입력

The first line contains two integers NN and HH (2≤N,H,N⋅H≤200,0002 \le N, H, N \cdot H \le 200\\,000): the number of puzzle pieces and the puzzle height, respectively.

Each of the remaining NN lines contains 2⋅H2 \cdot H integers: (j+1)(j+1)-st line describes the jj-th puzzle piece as A_j,1,B_j,1,…,A_j,H,B_j,HA\_{j,1}, B\_{j,1}, \ldots, A\_{j,H}, B\_{j,H} (0≤A_j,i<B_j,i≤1060 \le A\_{j,i} < B\_{j,i} \le 10^6), where A_j,iA\_{j,i} is the XX-coordinate of the left side and B_j,iB\_{j,i} the XX-coordinate of the right side of the ii-th rectangle of the jj-th piece.

It is known that each puzzle piece is a connected figure (A_j,i+1<B_j,iA\_{j,i+1} < B\_{j,i} and A_j,i<B_j,i+1A\_{j,i} < B\_{j,i+1} for all 1≤j≤N1 \le j \le N and 1≤i<H1 \le i < H).

출력

Output NN distinct integers, each in the range 1…N1 \ldots N: the numbers of the puzzle pieces in such an order that they form a perfect rectangle when laid out side by side. If there are several solutions, output any one of them. It is known that at least on soluton exists in each test case.

예제2

  1. 예제 1

    입력
    4 3
    0 2 0 1 0 2
    1 2 0 2 0 2
    0 3 1 2 1 2
    1 2 0 3 1 3
    
    예상 출력
    1 4 3 2
    
  2. 예제 2

    입력
    5 2
    1 3 2 3
    0 1 0 2
    0 3 1 2
    0 2 1 3
    1 2 0 3
    
    예상 출력
    2 3 5 4 1