#P7876. 「SWTR-7」Scores(hard version)

    ID: 6330 远端评测题 500ms 16MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>模拟2021Special JudgeO2优化图的建立,建图图遍历构造洛谷月赛

「SWTR-7」Scores(hard version)

Description

There are nn students in Xiao A's class. Recently, they took an exam with mm subjects. The score of student ii in subject jj is an integer si,j (0si,j100)s_{i,j}\ (0\leq s_{i,j}\leq 100).

Students care a lot about their rank in the class, so they often compare their scores with others. If a student ii has a higher score than jj in at least one subject, then they feel that they are not worse than jj. On the other hand, if they have a lower score than jj in every subject, then they feel they are completely crushed by jj.

In fact, the two situations above are not strictly opposite. However, Xiao A, who loves gossip, learned the score relationship between every pair of students, and he was surprised to find that: a student ii is either crushed by jj, or not worse than jj. At the same time, if ii and jj are both crushed by the same person, or they both crush the same person, then between ii and jj one of them is crushed by the other. We use a matrix ai,j (ij)a_{i,j}\ (i\neq j) to describe the relationships Xiao A knows: ai,j=0a_{i,j}=0 means ii is crushed by jj; ai,j=1a_{i,j}=1 means ii is not worse than jj.

Xiao A wants to know whether such a situation can actually happen, i.e. whether there exists an n×mn\times m score table ss that satisfies the score relationships described by matrix aa, so as to determine whether someone lied. If such an ss exists, first output YES\texttt{YES}, then output any valid score table that meets the requirements. Otherwise, output NO\texttt{NO}.

Note: the required conditions on ss are exactly the constraints given by aa, not only the properties Xiao A discovered, because those discovered properties are already reflected in the given aa.

Input Format

This problem contains multiple test cases.

The first line contains an integer tt, which indicates the test point ID.
The second line contains an integer TT, which indicates the number of test cases.

For each test case:
The first line contains two integers n,mn,m.
Then follow nn lines, each containing nn space-separated 0 or 1 values describing aa. The jj-th number in line i+1i+1 represents ai,ja_{i,j}.

In particular, to make input easier, it is defined that ai,i=0a_{i,i}=0. But you should know that it has no actual meaning.

Output Format

For each test case:

If there is no ss that satisfies the conditions, output one line with the string NO\texttt{NO}.
Otherwise, first output one line with the string YES\texttt{YES}, then output nn lines, each containing mm space-separated integers. The jj-th number in line i+1i+1 represents si,j (0si,j100)s_{i,j}\ (0\leq s_{i,j}\leq 100).

0
5
5 3
0 1 1 1 1
1 0 1 1 1
1 1 0 1 1
1 1 1 0 1
1 1 1 1 0
2 7
0 1
0 0
5 4
0 1 1 0 1
0 0 0 0 1
0 1 0 0 1
1 1 1 0 1
1 1 1 1 0
3 1
0 1 1
1 0 1
1 1 0
3 2
0 1 0
0 0 1
1 0 0
YES
100 99 97
98 100 99
95 97 100
0 98 100
99 99 99
YES
98 100 94 98 72 53 53
97 99 93 97 71 52 52
YES
90 80 70 60
50 40 30 20
60 50 40 30
100 90 80 70
40 60 80 100
NO
NO

Hint

"Special Judge"

This problem uses Special Judge. Please read the output format carefully. Incorrect output format may lead to UKE or WA.

The SPJ will first check whether your first line matches the correct answer.
If it matches and the answer is YES\texttt{YES}, then the SPJ will check whether your output satisfies all constraints.
If a solution exists and you output YES\texttt{YES} but your construction is wrong, you will get 50%50\% of the score for that test point.

The constraints you must satisfy are:

  • 0si,j1000\leq s_{i,j}\leq 100.
  • For any i,j (ij)i,j\ (i\neq j), if ai,j=0a_{i,j}=0, then for any k (1km)k\ (1\leq k\leq m), si,k<sj,ks_{i,k}<s_{j,k}; if ai,j=1a_{i,j}=1, then there exists a k[1,m]k\in [1,m] such that si,k>sj,ks_{i,k}>s_{j,k}.

You should note that all outputs must strictly follow the output format. If you correctly determine whether a solution exists, but in your output construction si,j<0s_{i,j}<0 or si,j>100s_{i,j}>100, the SPJ will judge it as WA and you will get 00 points, not 50% ×50\%\ \times the test point score.

"Constraints and Conventions"

This problem has 6 test points.

  • Testcase #0 (1 point): the sample.
  • Testcase #1 (10 points): n=1n=1.
  • Testcase #2 (10 points): m=1m=1.
  • Testcase #3 (30 points): m=2m=2.
  • Testcase #4 (20 points): ai,j=1 (ij)a_{i,j}=1\ (i\neq j).
  • Testcase #5 (29 points): no special constraints.

For 100%100\% of the data, 1n,m1001\leq n,m\leq 100, ai,j{0,1}a_{i,j}\in\{0,1\}, T=50T=50 (except Testcase #0).
For the constraints on aa: if ai,j=ai,k=0a_{i,j}=a_{i,k}=0, then at least one of aj,ka_{j,k} and ak,ja_{k,j} is 00; if ai,k=aj,k=0a_{i,k}=a_{j,k}=0, then at least one of ai,ja_{i,j} and aj,ia_{j,i} is 00.
For all test points, time limit is 500 ms, memory limit is 16 MB.

"Source"

Sweet Round 07 A2.
idea & solution & data: Alex_Wei; verification: chenxia25.

Translated by ChatGPT 5