QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 512 MB Total points: 100

#14175. TEST_68

Statistics

给定一棵 $n$ 个节点的树,第 $i$ 个点有一个权值 $a_i$。

对每个点 $x$,其的答案为其所在子树外的所有点中,选两个可以相同的点 $i,j$,$a_i$ 异或 $a_j$ 的最大值,如果选不出两个点,则认为 $x$ 的答案是 $0$。

输入格式

第一行一个数 $n$。

之后一行 $n-1$ 个数,第 $i$ 个数表示 $i+1$ 节点的父亲节点 $j$,保证 $j < i+1$。

之后一行 $n$ 个元素,第 $i$ 个元素表示第 $i$ 个点的权值 $a_i$。

输出格式

$n$ 行,每行一个数,其中第 $i$ 行的数表示第 $i$ 个节点对应的答案。

样例数据

样例 1 输入

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

样例 1 输出

0
15
12
15
15
15
14
15
15
15

子任务

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

对于 $10\%$ 的数据,满足 $1 \le n \le 10^2$。

对于另外 $20\%$ 的数据,满足 $1 \le n \le 10^4$。

对于另外 $30\%$ 的数据,树构成一条链。

对于另外 $20\%$ 的数据,满足 $0 \le a_i \le 10^2$。

对于 $100\%$ 的数据,满足 $1\le n\le 5 \times 10^5$,$ 0\le a_i \le 10^{18}$。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.