-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoj1659.cpp
More file actions
69 lines (61 loc) · 962 Bytes
/
Copy pathpoj1659.cpp
File metadata and controls
69 lines (61 loc) · 962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include<iostream>
using namespace std;
struct Node{
int d;
int p;
}node[10];
void qsort(int l, int r){
if(l>=r)
return;
int i=l;
int j=r+1;
Node key=node[i];
while(i<j){
while(i<j&&node[--j].d<=key.d);
node[i]=node[j];
while(i<j&&node[++i].d>=key.d);
node[j]=node[i];
}
node[i]=key;
qsort(l,i-1);
qsort(i+1,r);
}
int main(){
int t,n;
cin>>t;
for(int i=0;i<t;i++){
cin>>n;
for(int j=0;j<n;j++){
cin>>node[j].d;
node[j].p=j;
}
int m[10][10]={0};
for(int j=0;j<n;j++){
qsort(j,n-1);
for(int k=j+1;k<j+1+node[j].d;k++){
node[k].d--;
m[node[k].p][node[j].p]=1;
m[node[j].p][node[k].p]=1;
}
}
bool flag=true;
for(int j=0;j<10;j++){
if(node[j].d<0){
flag=false;
}
}
if(flag){
cout<<"YES"<<endl;
for(int j=0;j<n;j++){
for(int k=0;k<n;k++){
cout<<m[j][k]<<" ";
}
cout<<endl;
}
cout<<endl;
}else{
cout<<"NO"<<endl<<endl;
}
}
return 0;
}