Saturday, April 2, 2022

XOR Degree Graph

 MoEngage has given you an array 

D of length N. Construct a graph with N vertices such that:

  • The graph is connected and does not contain any parallel edges or self-loops;
  • Let du be the degree of vertex u (number of edges incident to u). Then, duDu;
  • i=1Ndi=0. In other words, the bitwise XOR of the degrees of all the vertices is 0.

If multiple such graphs exist, print any.

Input Format

  • The first line of input contains one integer T - the number of test cases you have to process. The descriptions of T test cases follow.
  • The first line contains one integer N - the size of the array D and the number of vertices to be present in the graph.
  • The second line contains N integers D1,D2,,DN - the elements of the array D.

Output Format

For each test case:

  • If it is impossible to construct such a graph, print NO in a single line.
  • Otherwise, print YES in a single line. Then, in the next N lines, print the adjacency matrix of the graph.
    The ith line should contain a string Ai of length N. The jth character of Ai is equal to 1 if there is an edge between the vertices i and j and 0 if there is no edge.

Note: The strings YES and NO are case-sensitive.

Constraints

  • 1T104
  • 2N2000
  • 1Di<N
  • Sum of N2 over all test cases does not exceed 107.

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 1: A possible graph satisfying all the conditions is:

Here, the degrees of the vertices is d=[1,1,2,2]. Note that, diDi (1i4). Also, the bitwise XOR of the degrees of all vertices is 1122=0.

Test case 2: There exists no graph that satisfies all the given conditions.

Test case 3: There exists no graph that satisfies all the given conditions.

Test case 4: A possible graph satisfying all the conditions is:

Here, the degrees of the vertices is d=[2,3,2,1,2]. Note that, diDi (1i5). Also, the bitwise XOR of the degrees of all vertices is 23212=0.

No comments:

Post a Comment

मुझे दिल में बसाना आसान नहीं....

पता है Recently i realised की मुझे दिल में बसाना आसान नहीं है बात-बात पे चिढ़ जाती हूं मैं दिल लगा लूं एक बार तो फिर ज़िद पे अड़...