#P5538. 【XR-3】Namid[A] me
【XR-3】Namid[A] me
Description
X gives you a tree with nodes, and each node has a weight.
You need to compute the value of the following expression modulo :
Here, is the value obtained by taking the bitwise AND of the weights of all nodes on the shortest path from to .
Hint: To make calculation easier, we define . Also, is a prime number and an uncommon NTT modulus, whose primitive root is . 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 , the number of nodes in the tree.
The second line contains positive integers , where is the weight of node .
The next lines each contain two positive integers , meaning there is an edge between node and node .
Constraints:
- .
- For all satisfying , .
- .
- Let be the number of leaves in the tree (nodes with degree ). The testdata guarantees that .
Output Format
Output one integer on one line, the answer modulo .
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
京公网安备 11011102002149号