Here XOR denotes the bitwise operator (^).
The first line of the input contains an integer, 'T,’ denoting the number of test cases. The first line of each test case contains two space-separated integers, ‘N’ and 'Q', denoting the number of nodes and the total queries operation to be performed. The next ‘N’-1 lines of each test case contain two integers representing an edge between the given indices. The next line of each test case contains ‘Q’ space-separated integers denoting the nodes of the tree on which query has to be performed.
For each test case, print ‘Q’ space-separated integers denoting the result of the queries. Print the output of each test case in a separate line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 10 0 <= N, Q <= 10^5 0 <= QUERY[i] < N Time Limit: 1 sec
The basic idea is to traverse the subtree for each given node in the query. We traverse the nodes using the DFS and compute the XOR value of the subtree while traversing the tree.
DFS(‘GRAPH’, ‘CURR’, ‘PREV’) (where ‘CURR’ is the current vertex and ‘PREV’ is the previous vertex traversed).