## GUPTA MECHANICAL

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

# [Solution] Accurate XOR CodeChef Solution

Chef has a tree consisting of $N$ nodes, rooted at node $1$. The parent of the ${i}^{th}\phantom{\rule{thickmathspace}{0ex}}\left(2\le i\le N\right)$ node in the tree is the node ${P}_{i}$.

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:-  👉
👇👇👇👇👇

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 $N-1$ space-separated integers ${P}_{2},{P}_{3},\dots ,{P}_{N}$, where ${P}_{i}$ denotes the parent-node of the ${i}^{th}$ node.

### Output Format

For each test case, print on a new line a binary string of length $N$ where the ${i}^{th}\phantom{\rule{thickmathspace}{0ex}}\left(1\le i\le N\right)$ 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

• $1\le T\le {10}^{5}$
• $2\le N\le 2\cdot {10}^{5}$
• $0\le K\le N$
• $1\le {P}_{i} for each $2\le i\le N$
• The sum of $N$ over all test cases won't exceed $2\cdot {10}^{5}$.