Answered step by step
Verified Expert Solution
Question
1 Approved Answer
HandsOn 2 : Nodes Reordering You are given a tree which consists of N nodes and an array A where A [ U ] represents
HandsOn
: Nodes Reordering
You are given a tree which consists of nodes and an array A where represents the value of node
You are also given an array where the parent of node is given by
We say that the path from to is considered good if for each pair of adjacent nodes the values written on these nodes satisfy the following condition:
is smaller than both and where is the bitwise xor operator
Find the maximum length of a good path that you can get.
Note:
It is given that
Input Format
The first line contains an integer, denoting the number of elements in
Each line of the subsequent lines where
Sample Test Cases
Case
Input:
Input:
Output:
Explanation:
The good path consists of nodes They satisfy the condition as the pair of value of nodes present in good path has a XOR equal to which is smaller than the values of the nodes.
Hence, the answer for this case is equal to
Case
Input:
Output:
Explanation:
Given
The good pafs consists of nodes They satisfy the condition as the pair of value of nodes present in good path has a XOR which is maller than the values of the nodes.
Hence, the answer for this case is equal to
Case
Input:
o
Output:
Explanation:
The good path consists of nodes They satisfy the condition as the pair of value of nodes present in good path has a XOR of which is smaller than the values of the nodes.
complete the function public static int getansint N List P List A
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started