Puzzle | 프로그래밍의 벗 PivotOJ
PivotOJ

Puzzle

시간 제한: 2000ms메모리 제한: 2048MB출처: EIO 2023-24 sel1BOJ 32977

문제

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 (2N,H,NH2000002 \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 2H2 \cdot H integers: (j+1)(j+1)-st line describes the jj-th puzzle piece as Aj,1,Bj,1,,Aj,H,Bj,HA_{j,1}, B_{j,1}, \ldots, A_{j,H}, B_{j,H} (0Aj,i<Bj,i1060 \le A_{j,i} < B_{j,i} \le 10^6), where Aj,iA_{j,i} is the XX-coordinate of the left side and Bj,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 (Aj,i+1<Bj,iA_{j,i+1} < B_{j,i} and Aj,i<Bj,i+1A_{j,i} < B_{j,i+1} for all 1jN1 \le j \le N and 1i<H1 \le i < H).

출력

Output NN distinct integers, each in the range 1N1 \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.

예제

예제 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

입력
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
이 문제는 채점 준비 중입니다. 테스트 데이터가 확보되면 제출이 가능합니다.