adplus-dvertising

Accurate XOR CodeChef Solution

We Are Discuss About CODECHEF SOLUTION

Accurate XOR CodeChef Solution

Accurate XOR CodeChef Solution

Chef has a tree consisting of¬†NN¬†nodes, rooted at node¬†11. The parent of the¬†ith(2‚ȧi‚ȧN)ith(2‚ȧi‚ȧN)¬†node in the tree is the node¬†PiPi.

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 NN nodes in the tree is exactly KK.

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¬†TT, denoting the number of test cases.
  • The first line of each test case contains two space-separated integers¬†NN¬†and¬†KK, denoting the number of vertices in the tree and the required sum of Xor-value respectively.
  • The second line of each test case contains¬†N‚ąí1N‚ąí1¬†space-separated integers¬†P2,P3,‚Ķ,PNP2,P3,‚Ķ,PN, where¬†PiPi¬†denotes the parent-node of the¬†ithith¬†node.

Output Format

For each test case, print on a new line a binary string of length¬†NN¬†where the¬†ith(1‚ȧi‚ȧN)ith(1‚ȧi‚ȧN)¬†character of the string denotes the binary value assigned to node¬†ii. If there are multiple ways to assign values to the node, you can do it in any way.

Accurate XOR CodeChef Solution

Constraints

  • 1‚ȧT‚ȧ1051‚ȧT‚ȧ105
  • 2‚ȧN‚ȧ2‚čÖ1052‚ȧN‚ȧ2‚čÖ105
  • 0‚ȧK‚ȧN0‚ȧK‚ȧN
  • 1‚ȧPi<i1‚ȧPi<i¬†for each¬†2‚ȧi‚ȧN2‚ȧi‚ȧN
  • The sum of¬†NN¬†over all test cases won’t exceed¬†2‚čÖ1052‚čÖ105.

Sample Input 1 

3
2 0
1
3 1
1 1
5 2
1 2 2 1

Sample Output 1 

00
100
11010

Explanation

Accurate XOR CodeChef Solution

Test case 11: The Xor-value of both nodes is 0.

Test case 22: The Xor-value of the node 11 is 11 and the remaining nodes have Xor-value 00.

Test case 33: The Xor-value of the nodes 1,41,4 is 11 and the remaining nodes have Xor-value 00.

SOLUTION

Accurate XOR CodeChef Solution

SOLUTION

Accurate XOR CodeChef Solution

SOLUTION

Yhaa You have done it but next? if YOU Want to Get Others Please Visit Here ScishowEngineer   Then Follow US HERE and Join Telegram.

If You Want To Learn Something New Then Visit Our Official Channel YOUTUBE

Related Posts

One thought on “Accurate XOR CodeChef Solution

Leave a Reply

Your email address will not be published.