Permutation Recovery

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

요약
각 열이 뒤섞인 2k x n 행렬이 주어질 때, 각 행과 그 역순열을 모으면 열별 중복집합이 되는 1..n의 순열 k개를 복원한다.
난이도

어려움10점 중 8점

유형
그래프, 유니온 파인드, 수학, 구현
정답자
아직 제출이 없습니다

문제

Initially, we had kk permutations of the integers from 11 to nn. We created a 2k×n2k \times n matrix by writing each permutation as well as its inverse in its own row. However, we forgot the permutations, and someone shuffled every column. Given this matrix, can you determine any set of permutations which we could have started with?

입력

The first line contains two integers nn and kk (1≤n≤4⋅1041 \leq n \leq 4 \cdot 10^4, 1≤k≤71 \leq k \leq 7).

The ii-th of the following 2k2k lines contains nn integers a_ija\_{ij}, the ii-th row of the matrix (1≤a_ij≤n1 \leq a\_{ij} \leq n).

It is guaranteed that the matrix could have been obtained as described above.

출력

Output kk lines. Each of them should contain a permutation of the integers from 11 to nn. After writing these permutations as well as their inverses in the rows of a 2k×n2k \times n matrix, it must be possible to obtain the input matrix by reordering the values in every column.

If there are multiple solutions, output any of them.

예제2

  1. 예제 1

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

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