#P6580. [Ynoi2019] 美好的每一天~ 不连续的存在

[Ynoi2019] 美好的每一天~ 不连续的存在

Description

Otonashi Ayana gives you an array AA, and a tree with nn nodes. Each node has a color, which is an integer from 11 to xx.

There are mm queries. For each query, only the nodes in [l,r][l,r] are kept on the tree. For a maximal connected component, let tt be the number of colors that appear an odd number of times in it. Then its contribution to the answer is AtA_t. That is, the answer is the sum of contributions of all connected components. Queries are independent of each other.

Input Format

The first line contains three integers n,m,xn, m, x separated by spaces.

The second line contains nn integers representing the color of each node.

The next n1n - 1 lines each contain two integers x,yx, y separated by spaces, indicating an edge.

Then one line contains x+1x + 1 integers representing A0A_0 to AxA_x.

Then mm lines follow, each containing two integers l,rl, r separated by spaces, representing one query.

Output Format

Output mm lines. Each line contains one integer, the answer to this query.

6 3 5
1 1 4 5 1 4
1 2
2 3
3 4
4 5
5 6
1 1 4 5 1 4
1 1
4 5
1 4
1
4
4

Hint

Idea: nzhtl1477, Solution: nzhtl1477, Code: nzhtl1477, Data: nzhtl1477.

Note: This problem uses bundled tests. Only after you pass all test points in a subtask can you get the score for that subtask.

For 1%1\% of the testdata, it is Sample 1.

For another 9%9\% of the testdata, n,m200n, m \leq 200.

For another 19%19\% of the testdata, n,m2000n, m \leq 2000.

For another 19%19\% of the testdata, x10x \leq 10.

For 100%100\% of the testdata, 1n,m1051 \leq n, m \leq 10^5, 1x,Ai1041 \leq x, A_i \leq 10^4.

Translated by ChatGPT 5