Frogs ' Neighborhood
| Time Limit: 5000MS |
|
Memory Limit: 10000K |
| Total Submissions: 7920 |
|
Accepted: 3392 |
|
Special Judge |
Description
Peiling a total of N size Lakes L1, l2, ..., Ln(which includes peiling), each lake Li has a frog Fi(1≤ i ≤ N). If there is a waterway connection between the lake Li and Lj , the Frog Fi and Fj each other as neighbors. It is now known that the number of neighbors per frog x1, x2, ..., xn, please give a link to each of the two lakes.
Input
The first line is the number of groups of test data T(0≤ t ≤20). Each group of data consists of two rows, the first line is an integer n (2 < N < 10), the second row is n integers,x1, x2,..., xN (0≤ XI ≤ N).
Output
For each set of test data entered, if there is no possible connection, output "no". Otherwise, the output is " YES" and an n-n Matrix represents the neighboring relationship between lakes, that is, if Lake i is connected to Lake J by Waterway, the first row The J number is 1, otherwise 0. Output a space between each of the two numbers. If there is more than one possibility, just give a condition that matches the situation. Output a blank line between two adjacent sets of test data.
Sample Input
Sample Output
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6#include <string>7#include <vector>8#include <stack>9#include <queue>Ten#include <Set> One#include <map> A#include <iomanip> - using namespacestd; - Const intinf=0x5fffffff; the Const intms= the; - Const Doubleexp=1e-8; - structnode - { + intdegree; - intID; + BOOL operator< (ConstNode &b)Const A { at returnDegree>B.degree; - } - }nodes[ms]; - - intEdges[ms][ms]; - in intMain () - { to inti,j,k; + intn,t; -Cin>>T; the while(t--) * { $Cin>>N;Panax Notoginseng for(i=0; i<n;i++) - { theCin>>Nodes[i].degree; +Nodes[i].id=i; A } thememset (Edges,0,sizeof(edges)); + intflag=1; - for(k=0; k<n&&flag;k++) $ { $Sort (nodes+k,nodes+n); -I=nodes[k].id; - intdu=Nodes[k].degree; the if(du>n-k-1) -flag=0;Wuyi for(ints=1; s<=du&&flag;s++) the { -j=nodes[s+k].id; Wu if(nodes[s+k].degree<=0) -flag=0; Aboutnodes[s+k].degree--; $edges[i][j]=edges[j][i]=1; - - } - } A if(flag) + { thecout<<"YES"<<Endl; - for(i=0; i<n;i++) $ { the for(j=0; j<n;j++) the { the if(j) thecout<<" "; -cout<<Edges[i][j]; in } thecout<<Endl; the } About } the Else thecout<<"NO"<<Endl; the if(T) +cout<<Endl; - } the return 0;Bayi}
Frogs ' Neighborhood