QOJ.ac

QOJ

実行時間制限: 3 s メモリ制限: 512 MB 満点: 100

#14175. TEST_68

統計

Given a tree with $n$ nodes, each node $i$ has a weight $a_i$.

For each node $x$, the answer is the maximum XOR sum $a_i \oplus a_j$ of two nodes $i$ and $j$ (which can be the same) chosen from all nodes outside the subtree rooted at $x$. If it is impossible to choose two such nodes, the answer for $x$ is $0$.

Input

The first line contains an integer $n$.

The next line contains $n-1$ integers, where the $i$-th integer represents the parent $j$ of node $i+1$, with the guarantee that $j < i+1$.

The next line contains $n$ integers, where the $i$-th integer represents the weight $a_i$ of node $i$.

Output

Output $n$ lines, where the $i$-th line contains the answer for node $i$.

Examples

Input 1

10
1 1 2 3 2 3 6 7 7
10 6 4 10 8 10 5 3 5 4

Output 1

0
15
12
15
15
15
14
15
15
15

Subtasks

Idea: nzhtl1477, Solution: zx2003, Code: nzhtl1477, Data: nzhtl1477

For $10\%$ of the data, $1 \le n \le 10^2$.

For another $20\%$ of the data, $1 \le n \le 10^4$.

For another $30\%$ of the data, the tree is a chain.

For another $20\%$ of the data, $0 \le a_i \le 10^2$.

For $100\%$ of the data, $1 \le n \le 5 \times 10^5$ and $0 \le a_i \le 10^{18}$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.