HDU -> ACM -> Frogs' Neighborhood

Problem Description

There are N large and small lakes L 1 , L 2 , ..., L n near Weiming Lake ( including Weiming Lake), and in each lake Li lives a frog F i ( 1 ≤ iN ). If the lakes Li and L j are connected by a waterway, the frogs F i and F j are called neighbors to each other. Now that each frog has the number of neighbors x 1 , x 2 , ..., x n , please give the connection between each two lakes.

 

Input
<p>The first line is the number of groups of test data <i>T</i> (0 ≤ <i>T</i> ≤ 20). Each set of data includes two lines, the first line is integer N (2 < <i>N</i> < 10), the second line is <i>N</i> integers, <i>x</i ><sub>1</sub>, <i>x</i><sub>2</sub>,..., <i>x</i><sub>n</sub>(0 ≤ <i>x<sub>i</sub></i> ≤ <i>N</i>). </p>
 

Output
<p>For each set of input test data, if there is no possible connection, output "NO". Otherwise, output "YES", and use a matrix of <i>N</i>×<i>N</i> to represent the adjacent relationship between lakes, that is, if lake <i>i</i> and lake <i> There is a waterway between j</i>, then the <i>j</i> digit of the <i>i</i> line is 1, otherwise it is 0. Output a space between every two numbers. If there are multiple possibilities, just give one that meets the conditions. A blank line is output between two adjacent sets of test data. </p>
 

Sample Input
 
  
3 7 4 3 1 5 4 2 1 6 4 3 1 4 2 0 6 2 3 1 1 2 1
 

Sample Output
 
  
YES 0 1 0 1 1 0 1 1 0 0 1 1 0 0 0 0 0 1 0 0 0 1 1 1 0 1 1 0 1 1 0 1 0 1 0 0 0 0 1 1 0 0 1 0 0 0 0 0 0 NO YES 0 1 0 0 1 0 1 0 0 1 1 0 0 0 0 0 0 1 0 1 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324650910&siteId=291194637