#P5538. 【XR-3】Namid[A] me

    ID: 4495 远端评测题 3000ms 250MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>图论O2优化树的应用位运算,按位

【XR-3】Namid[A] me

Description

X gives you a tree with nn nodes, and each node has a weight.

You need to compute the value of the following expression modulo 786433786433:

1uvnf(u,v)f(u,v)\sum_{1\leq u\leq v\leq n}f(u,v)^{f(u,v)}

Here, f(u,v)f(u,v) is the value obtained by taking the bitwise AND of the weights of all nodes on the shortest path from uu to vv.

Hint: To make calculation easier, we define 00=00^0=0. Also, 786433786433 is a prime number and an uncommon NTT modulus, whose primitive root is 1010. If you do not know what NTT is or what a primitive root is, you can ignore this hint.

Input Format

The first line contains a positive integer nn, the number of nodes in the tree.

The second line contains nn positive integers a1na_{1\dots n}, where aia_i is the weight of node ii.

The next n1n-1 lines each contain two positive integers u,vu,v, meaning there is an edge between node uu and node vv.

Constraints:

  • 2n2×1052 \le n \le 2 \times 10^5.
  • For all ii satisfying 1in1\le i \le n, 1ai<2301 \le a_i < 2^{30}.
  • 1u,vn,uv1 \le u,v \le n, u \ne v.
  • Let dd be the number of leaves in the tree (nodes with degree 11). The testdata guarantees that 4nd3×1064\le n \cdot d \le 3 \times 10 ^ 6.

Output Format

Output one integer on one line, the answer modulo 786433786433.

10
15 50 89 9 38 73 38 23 6 52
2 1
3 2
4 2
5 3
6 3
7 5
8 7
9 1
10 7

54184

20
17 56 72 12 16 43 33 8 28 90 21 12 7 43 55 95 25 65 63 77
2 1
3 2
4 1
5 3
6 5
7 1
8 7
9 7
10 3
11 5
12 7
13 5
14 7
15 11
16 6
17 3
18 15
19 15
20 13

503636

Hint

Translated by ChatGPT 5