#P5619. [DBOI2019] 持矢

[DBOI2019] 持矢

Description

dobydoby is an archer, and he really likes holding arrows.

One day, he came to an archery range and found that the owner had set up nn targets (numbered from 1n1-n). Between them, n1n-1 lines were drawn so that the nn targets and the n1n-1 lines form a tree rooted at 11. Each target has a score value.

To train himself, he chooses a node (called the parent node), then shoots once at every target in its subtree (including itself). Each target is hit with probability 50%50\%. After finishing shooting a subtree, the total score he gets is the product of the scores of all targets that were hit.

Now he wants to know: if he chooses different nodes as the parent node, what is his expected total score? Since the total score may be very large, you need to take the result modulo 1926081719260817 (a prime).

Input Format

The first line contains two positive integers nn and mm, the number of targets and the number of queries.

The next line contains nn positive integers, representing the scores of targets numbered 1n1-n.

The next n1n-1 lines each contain two integers u,vu,v, describing an undirected edge of the tree.

The next mm lines each contain one positive integer x(1xn)x(1\leq x\leq n), meaning a query for the expected total score that dobydoby obtains when target xx is chosen as the parent node.

Output Format

Output one line with one positive integer outout.

To reduce output, define outout as the sum of the expected total scores over all queries. Since this is an expectation, when computing ab\frac{a}{b}, you should compute it as ab1mod(19260817)a*b^{-1} mod (19260817). You also need to take outout modulo 1926081719260817.

2 1
1 2
2 1
1
14445614
5 3
4 4 3 4 5
1 2
3 2
2 4
5 4
3
2
1
16251447

Hint

Note: Since the modulus is large, be careful about overflow of intermediate results when computing modular inverses.

If you do not need extreme optimization, using fast exponentiation to compute modular inverses is enough.

[Sample #11 Explanation]

The answer is 54\frac{5}{4}. The possible total scores are 00, 11, and 22.

[Sample #22 Explanation]

The answers are 96304109630410, 1083424710834247, and 1504760715047607, i.e. 32\frac{3}{2}, 59916\frac{599}{16}, and 299932\frac{2999}{32}.

SubtaskSubtask #11 (1010 points):

1n,m101\leq n,m\leq 10.

SubtaskSubtask #22 (4040 points):

1n,m1000001\leq n,m\leq 100000.

SubtaskSubtask #33 (5050 points):

1n,m20000001\leq n,m\leq 2000000.

For all test points, the time limit is 1.5s1.5s, and the memory limit is 125M125M.

Problem setter: 1jia11jia1

Translated by ChatGPT 5