![]() |
||||||||||
|
||||||||||
Query on A TreeTime Limit: 20000/10000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others)Total Submission(s): 4600 Accepted Submission(s): 1437 Problem Description Monkey A lives on a tree, he always plays on this tree. One day, monkey A learned about one of the bit-operations, xor. He was keen of this interesting operation and wanted to practise it at once. Monkey A gave a value to each node on the tree. And he was curious about a problem. The problem is how large the xor result of number x and one node value of label y can be, when giving you a non-negative integer x and a node label u indicates that node y is in the subtree whose root is u(y can be equal to u). Can you help him? Input There are no more than 6 test cases. For each test case there are two positive integers n and q, indicate that the tree has n nodes and you need to answer q queries. Then two lines follow. The first line contains n non-negative integers $V_1,V_2,\cdots,V_n$, indicating the value of node i. The second line contains n-1 non-negative integers $F_1,F_2,\cdots\,F_{n-1}$, $F_i$ means the father of node $i+1$. And then q lines follow. In the i-th line, there are two integers u and x, indicating that the node you pick should be in the subtree of u, and x has been described in the problem. $2 \leq n,q \leq 10^5$ $0 \leq V_i \leq 10^9$ $1 \leq F_i \leq n$, the root of the tree is node 1. $1 \leq u \leq n,0 \leq x \leq 10^9$ Output For each query, just print an integer in a line indicating the largest result. Sample Input
Sample Output
Source | ||||||||||
|