#Lutece2565. Qyery on a tree
Qyery on a tree
Migrated from Lutece 2565 Qyery on a tree
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
给定一棵 个节点的树,节点编号从 到 ,指定 号节点为根节点,每个节点有权值 ,计算下面这个式子的值:
$$\sum_{i=1}^n \sum_{j=i+1}^n [a_i \oplus a_j =a_{\text{LCA}(i,j)}](i \oplus j) $$其中, 表示树上 与 的最近公共祖先。
Input
第一行给出节点个数 。 第二行给出 个整数,从 到 。 接下来的 行,每行给出两个数 和 ,表示节点 和 间连有一条边。
Output
输出一个正整数表示答案。
Samples
6
4 2 1 6 6 5
1 2
2 3
1 4
4 5
4 6
18
Constraints
且
Note
LCA:指两个节点的最近公共祖先。 这个定义只有在指定了根节点的情况下才有效。 表达式 在 为真的情况下值为 ,否则值为 。
Resources
2021 UESTC ICPC Training for Data Structures