[Solution] Accurate XOR CodeChef Solution
Chef has a tree consisting of nodes, rooted at node . The parent of the node in the tree is the node .
Chef wants to assign a binary value (0
or 1
) to every node of the tree. The Xor-value of a node is defined as the bitwise XOR of all the binary values present in the subtree of that node.
Help Chef to assign values to the nodes of the tree in such a way that the sum of Xor-value of all the nodes in the tree is exactly .
It can be shown that such an assignment always exists. If there are multiple possible answers, you
may print any of them.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- The first line of each test case contains two space-separated integers and , denoting the number of vertices in the tree and the required sum of Xor-value respectively.
- The second line of each test case contains space-separated integers , where denotes the parent-node of the node.
Output Format
For each test case, print on a new line a binary string of length where the character of the string denotes the binary value assigned to node . If there are multiple ways to assign values to the node, you can do it in any way.
Constraints
- for each
- The sum of over all test cases won't exceed .
No comments:
Post a Comment