Table Compression | 프로그래밍의 벗 PivotOJ
PivotOJ

Table Compression

시간 제한: 4000ms메모리 제한: 1024MB출처: MOOI 2015-16 finalBOJ 30816

문제

Little Petya is now fond of data compression algorithms. He has already studied gz, bz, zip algorithms and many others. Inspired by the new knowledge, Petya is now developing the new compression algorithm which he wants to name dis.

Petya decided to compress tables. He is given a table aa consisting of nn rows and mm columns that is filled with positive integers. He wants to build the table aa' consisting of positive integers such that the relative order of the elements in each row and each column remains the same. That is, if in some row ii of the initial table ai,j<ai,ka_{i,j} < a_{i,k}, then in the resulting table ai,j<ai,ka'_{i,j} < a'_{i,k}, and if ai,j=ai,ka_{i,j} = a_{i,k} then ai,j=ai,ka'_{i,j} = a'_{i,k}. Similarly, if in some column jj of the initial table ai,j<ap,ja_{i,j} < a_{p,j} then in compressed table ai,j<ap,ja'_{i,j} < a'_{p,j} and if ai,j=ap,ja_{i,j} = a_{p,j} then ai,j=ap,ja'_{i,j} = a'_{p,j}.

Because large values require more space to store them, the maximum value in aa' should be as small as possible.

Petya is good in theory, however, he needs your help to implement the algorithm.

입력

The first line of the input contains two integers nn and mm (1n,m and nm1000000)1 \leqslant n,m \ \text{and} \ n \cdot m \leqslant 1\,000\,000), the number of rows and the number of columns of the table respectively.

Each of the following nn rows contain mm integers ai,ja_{i,j} (1ai,j109)(1 \leqslant a_{i,j} \leqslant 10^{9}) that are the values in the table.

출력

Output the compressed table in form of nn lines each containing mm integers.

If there exist several answers such that the maximum number in the compressed table is minimum possible, you are allowed to output any of them.

힌트

In the first sample test, despite the fact a1,2a21a_{1,2} \ne a_{2 1}, they are not located in the same row or column so they may become equal after the compression.

예제

예제 1

입력
2 2
1 2
3 4
출력
1 2
2 3

예제 2

입력
4 3
20 10 30
50 40 30
50 60 70
90 80 70
출력
2 1 3
5 4 3
5 6 7
9 8 7
이 문제는 채점 준비 중입니다. 테스트 데이터가 확보되면 제출이 가능합니다.