MoEngage has given you an array
of length . Construct a graph with vertices such that:
- The graph is connected and does not contain any parallel edges or self-loops;
- Let be the degree of vertex (number of edges incident to ). Then, ;
- . In other words, the bitwise XOR of the degrees of all the vertices is .
If multiple such graphs exist, print any.
Input Format
- The first line of input contains one integer - the number of test cases you have to process. The descriptions of test cases follow.
- The first line contains one integer - the size of the array and the number of vertices to be present in the graph.
- The second line contains integers - the elements of the array .
Output Format
For each test case:
- If it is impossible to construct such a graph, print in a single line.
- Otherwise, print in a single line. Then, in the next lines, print the adjacency matrix of the graph.
The line should contain a string of length . The character of is equal to1
if there is an edge between the vertices and and0
if there is no edge.
Note: The strings and are case-sensitive.
Constraints
- Sum of over all test cases does not exceed .
Sample Input 1
4
4
1 2 2 2
4
2 1 1 1
5
2 2 2 2 2
5
2 3 2 2 2
Sample Output 1
YES
0001
0010
0101
1010
NO
NO
YES
01010
10101
01001
10000
01100
Explanation
Test case : A possible graph satisfying all the conditions is:
Here, the degrees of the vertices is . Note that, . Also, the bitwise XOR of the degrees of all vertices is .
Test case : There exists no graph that satisfies all the given conditions.
Test case : There exists no graph that satisfies all the given conditions.
Test case : A possible graph satisfying all the conditions is:
Here, the degrees of the vertices is . Note that, . Also, the bitwise XOR of the degrees of all vertices is .
No comments:
Post a Comment