#P8511. [Ynoi Easy Round 2021] TEST_68
[Ynoi Easy Round 2021] TEST_68
Problem Description
Given a tree with nodes, node has a weight .
For each node , its answer is defined as follows: among all nodes outside the subtree of , choose two nodes (they may be the same node), and maximize xor . If it is impossible to choose two nodes, then the answer for is .
Input Format
The first line contains an integer .
The next line contains integers. The -th integer denotes the parent node of node , and it is guaranteed that .
The next line contains integers. The -th integer denotes the weight of node .
Output Format
Output lines, each containing one integer. The integer on the -th line is the answer for node .
10
1 1 2 3 2 3 6 7 7
10 6 4 10 8 10 5 3 5 4
0
15
12
15
15
15
14
15
15
15
Hint
Idea: nzhtl1477, Solution: zx2003, Code: nzhtl1477, Data: nzhtl1477.
For of the testdata, .
For another of the testdata, .
For another of the testdata, the tree is a chain.
For another of the testdata, .
For of the testdata, and .
Translated by ChatGPT 5