AtCoder Regular Contest 208 (Div. 2)
D
Symmetric Matrix
AtCoder
⌀ 3070
原题
← CE →
翻译中…

Problem Statement

翻译中…

You are given an integer sequence $Y=(Y_1,Y_2,\ldots,Y_N)$ of length $N$ where each element is between $1$ and $N$ inclusive.

翻译中…

Determine whether there exists an $N \times N$ integer matrix $A=(A_{i,j})$ $(1\le i , j \le N)$ that satisfies all of the following conditions, and if it exists, find one such matrix.

翻译中…
  • $1\le A_{i,j} \le N$ $(1\le i \le N, 1\le j\le N)$
  • $A_{i,j}=A_{j,i}$ $(1\le i\le N, 1\le j\le N)$
  • $A_{i,j_1}\neq A_{i,j_2}$ $(1\le i\le N, 1\le j_1 < j_2 \le N)$
  • $A_{i,Y_i}=1$ $(1\le i\le N)$
翻译中…

You are given $T$ test cases; solve each of them.

翻译中…

Constraints

翻译中…
  • $1\le T\le 5000$
  • $1\le N \le 500$
  • The sum of $N^2$ over all test cases is at most $500^2$.
  • $1\le Y_i\le N$
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T

翻译中…

Each test case is given in the following format:

翻译中…

N
Y_1 Y_2 \ldots Y_N

翻译中…

Output

翻译中…

Output the answers for each test case in order, separated by newlines.

翻译中…

For each test case, if there does not exist an $A$ that satisfies all conditions, print No.

翻译中…

Otherwise, print $A$ that satisfies all conditions in the following format:

翻译中…

Yes
A_{1,1} A_{1,2} \ldots A_{1,N}
A_{2,1} A_{2,2} \ldots A_{2,N}
\vdots
A_{N,1} A_{N,2} \ldots A_{N,N}

翻译中…

If there are multiple $A$ that satisfy all conditions, any of them will be accepted.

翻译中…

样例

Input #1
4
3
1 3 2
3
1 2 3
1
1
5
1 3 2 5 4
Output #1
Yes
1 2 3
2 3 1
3 1 2
No
Yes
1
Yes
1 2 5 4 3
2 3 1 5 4
5 1 4 3 2
4 5 3 2 1
3 4 2 1 5
Consider the first test case. It can be verified that the $A$ in the sample output satisfies all conditions. Other than this, for example, the following $A$ will also be accepted:
题目信息
题号
arc208_d
时间限制
2 s
内存限制
1024 MB

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