Logo
(追記) (追記ここまで)

31116번 - Hamilton 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB333100.000%

문제

Bobo has an $n \times n$ symmetric matrix $C$ consisting of zeros and ones. For a permutation $p_1, \dots, p_n$ of 1,ドル \dots, n,ドル let $$ c_i = \begin{cases} C_{p_i, p_{i + 1}} & \text{for } 1 \leq i < n \\ C_{p_n, p_1} & \text{for } i = n \\ \end{cases}\text{.}$$

The permutation $p$ is almost monochromatic if and only if the number of indices $i$ (1ドル \leq i < n$) where $c_i \neq c_{i + 1}$ is at most one.

Find an almost monochromatic permutation $p_1, \dots, p_n$ for the given matrix $C$.

입력

The input consists of several test cases terminated by end-of-file. For each test case,

The first line contains an integer $n$.

For the following $n$ lines, the $i$-th line contains $n$ integers $C_{i, 1}, \dots, C_{i, n}$.

출력

For each test case, if there exists an almost monochromatic permutation, output $n$ integers $p_1, \dots, p_n$ which denote the permutation. Otherwise, output $-1$.

If there are multiple almost monochromatic permutations, any of them is considered correct.

제한

  • 3ドル \le n \le 2000$
  • $C_{i, j} \in \{0, 1\}$ for each 1ドル \leq i, j \leq n$
  • $C_{i, j} = C_{j, i}$ for each 1ドル \leq i, j \leq n$
  • $C_{i, i} = 0$ for each 1ドル \leq i \leq n$
  • In each input, the sum of $n$ does not exceed 2000ドル$.

예제 입력 1

3
001
000
100
4
0000
0000
0000
0000

예제 출력 1

3 1 2
2 4 3 1

노트

For the first test case, $c_1 = C_{3, 1} = 1,ドル $c_2 = C_{1, 2} = 0,ドル $c_3 = C_{2, 3} = 0$. Only when $i = 1,ドル $c_i \neq c_{i + 1}$. Therefore, the permutation 3,ドル 1, 2$ is an almost monochromatic permutation.

출처

Contest > Open Cup > 2020/2021 Season > Stage 18: Grand Prix of Beijing G번

(追記) (追記ここまで)

출처

대학교 대회

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

AltStyle によって変換されたページ (->オリジナル) /