Codeforces Round 912 (Div. 2)
B
StORage room
Codeforces
1200
原题
← AC →
翻译中…

In Cyprus, the weather is pretty hot. Thus, Theofanis saw this as an opportunity to create an ice cream company.

翻译中…

He keeps the ice cream safe from other ice cream producers by locking it inside big storage rooms. However, he forgot the password. Luckily, the lock has a special feature for forgetful people!

翻译中…

It gives you a table $M$ with $n$ rows and $n$ columns of non-negative integers, and to open the lock, you need to find an array $a$ of $n$ elements such that:

翻译中…
  • $0 \le a_i \lt 2^{30}$, and
  • $M_{i,j} = a_i | a_j$ for all $i \neq j$, where $|$ denotes the bitwise OR operation.
翻译中…

The lock has a bug, and sometimes it gives tables without any solutions. In that case, the ice cream will remain frozen for the rest of eternity.

翻译中…

Can you find an array to open the lock?

翻译中…

Input

翻译中…

The first line contains a single integer $t$ ($1 \le t \le 10^{3}$) — the number of test cases.

翻译中…

The first line of each test case contains a single integer $n$ ($1 \le n \le 10^{3}$) — the size of the hidden array.

翻译中…

The next $n$ lines describe the rows of $M$, line $i$ contains the table values $M_{i,1}, M_{i,2}, \ldots, M_{i,n}$ ($0 \le M_{i,j} \lt 2^{30}$).

翻译中…

It is guaranteed that $M_{i,i} = 0$ and $M_{i,j} = M_{j,i}$ for all $1 \le i,j \le n$.

翻译中…

It is also guaranteed that the sum of $n$ over all test cases does not exceed $10^{3}$.

翻译中…

Output

翻译中…

For each test case, if there is a solution print YES and an array that satisfies the property, otherwise print NO.

翻译中…

If there are multiple solutions, print any of them.

翻译中…

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

翻译中…

样例

Input #1
4
1
0
4
0 3 3 5
3 0 3 7
3 3 0 7
5 7 7 0
5
0 7 7 5 5
7 0 3 2 6
7 3 0 3 7
5 2 3 0 4
5 6 7 4 0
3
0 0 1
0 0 0
1 0 0
Output #1
YES
7
YES
1 3 2 5
YES
5 2 3 0 4
NO
InputCopy OutputCopy
题目信息
题号
1903B
时间限制
2 s
内存限制
256 MB
标签
位运算
暴力
构造
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。