Movatterモバイル変換


[0]ホーム

URL:


Logo

33332번 -Single-Crossing스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초2048 MB0000.000%

문제

The summer has already been long and boring, and to entertain yourself, you started to look over some recent papers. You stumbled upon an interesting problem: Let's consider a list of $n$ permutations $X^1, \ldots, X^n$ over $\{1, 2, \ldots, m\}$. In other words, each $X^i$ is a vector $X^i_1, \ldots, X^i_m$ of size $m$ in which all the numbers from $1$ to $m$ appear exactly once. The paper is about rearranging the given permutations such that the new order, let it be $Y^1, \ldots, Y^n$, is single-crossing.

A sequence of permutations $Y^1, \ldots, Y^n$ is calledsingle-crossing if and only if, when we choose any three indices $1 \leq i < j < k \leq n$ and any two distinct values $1 \leq a, b \leq m$ such that $a$ appears before $b$ in both $Y^i$ and $Y^k$, it holds that $a$ appears before $b$ in $Y^j$ as well.

In a more intuitive way: we say that $Y^1, \ldots, Y^n$ is single-crossing if and only if any two elements $a$ and $b$ change their relative order at most once (see the image above).

You can't find the paper anymore, but you really want to implement a solution for the problem it proposes. So, given $t$ test cases, find out for each of them if there is such a way to rearrange the permutations to be single-crossing, and, if so, output one possible solution.

입력

The first line contains one number $t$ ($1 \leq t \leq 5$), the number of test cases.

Each test case is described as follows. The first line contains two integers $n$ and $m$ ($1 \leq n \leq 10^5$; $1 \leq n \cdot m \leq 10^6$). Each of the next $n$ lines contains $m$ integers: the permutations $X^1, \ldots, X^n$.

출력

For each of the $t$ test cases, print a single line. If there is no way to rearrange the permutations so that the sequence becomes single-crossing, print-1. Otherwise, print a permutation $p$ containing $n$ space-separated integers: the order in which the original permutations could be rearranged.

If there are multiple solutions, output any one of them.

제한

예제 입력 1

25 42 3 1 41 2 3 42 1 3 44 3 2 13 2 4 14 42 1 3 41 2 3 42 1 4 31 2 4 3

예제 출력 1

2 3 1 5 4-1

힌트

first test case,ordered as 2 3 1 5 4:1 2 3 42 1 3 42 3 1 43 2 4 14 3 2 1

출처

Camp > Petrozavodsk Programming Camp > Summer 2024 > Day 7: Farewell Contest L번

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일:contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호


[8]ページ先頭

©2009-2025 Movatter.jp