GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Wednesday, 20 July 2022

[Solution] Accurate XOR CodeChef Solution



Chef has a tree consisting of N nodes, rooted at node 1. The parent of the ith(2iN) node in the tree is the node Pi.

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 N nodes in the tree is exactly K.

It can be shown that such an assignment always exists. If there are multiple possible answers, you

Solution Click Below:-  👉CLICK HERE👈
👇👇👇👇👇

 may print any of them.

Input Format

  • The first line of input will contain a single integer T, denoting the number of test cases.
  • The first line of each test case contains two space-separated integers N and K, denoting the number of vertices in the tree and the required sum of Xor-value respectively.
  • The second line of each test case contains N1 space-separated integers P2,P3,,PN, where Pi denotes the parent-node of the ith node.

Output Format

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

Constraints

  • 1T105
  • 2N2105
  • 0KN
  • 1Pi<i for each 2iN
  • The sum of N over all test cases won't exceed 2105.

No comments:

Post a Comment