#P6580. [Ynoi2019] 美好的每一天~ 不连续的存在
[Ynoi2019] 美好的每一天~ 不连续的存在
Description
Otonashi Ayana gives you an array , and a tree with nodes. Each node has a color, which is an integer from to .
There are queries. For each query, only the nodes in are kept on the tree. For a maximal connected component, let be the number of colors that appear an odd number of times in it. Then its contribution to the answer is . 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 separated by spaces.
The second line contains integers representing the color of each node.
The next lines each contain two integers separated by spaces, indicating an edge.
Then one line contains integers representing to .
Then lines follow, each containing two integers separated by spaces, representing one query.
Output Format
Output 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 of the testdata, it is Sample 1.
For another of the testdata, .
For another of the testdata, .
For another of the testdata, .
For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号