#P6623. [省选联考 2020 A 卷] 树
[省选联考 2020 A 卷] 树
Description
Given a rooted tree with nodes. The nodes are numbered starting from . The root is node . Each node has a positive integer weight .
Let the node numbers of all nodes in the subtree of node (including itself) be . Define the value of as:
$val(x)=(v_{c_1}+d(c_1,x)) \oplus (v_{c_2}+d(c_2,x)) \oplus \cdots \oplus (v_{c_k}+d(c_k, x))$
Here, denotes the number of edges on the unique simple path between nodes and in the tree, and . denotes the XOR operation.
Please compute .
Input Format
The first line contains a positive integer , representing the size of the tree.
The second line contains positive integers, representing .
The next line contains positive integers, in order representing the parent index of nodes to .
Output Format
Only one line containing one integer, representing the answer.
5
5 4 1 2 3
1 1 2 2
12
Hint
[Sample Explanation 1]
$val(1)=(5+0)\oplus(4+1)\oplus(1+1)\oplus(2+2)\oplus(3+2)=3$.
.
.
.
.
The sum is .
[Constraints]
For of the testdata: .
For of the testdata: .
Another of the testdata: all ().
Another of the testdata: all ().
For of the testdata: , .
Translated by ChatGPT 5
京公网安备 11011102002149号