QOJ.ac

QOJ

Límite de tiempo: 3 s Límite de memoria: 64 MB Puntuación total: 100

#11271. A Beautiful Every Day ~ Discontinuous Existence

Estadísticas

Ayanami Ayana gives you an array $A$ and a tree with $n$ nodes, where each node has a color represented by an integer from $1$ to $x$.

There are $m$ queries. For each query, only nodes with indices in the range $[l, r]$ are kept in the tree. For each maximal connected component, let $t$ be the number of colors that appear an odd number of times within that component. The contribution of this component to the answer is $A_t$. The total answer is the sum of contributions from all such connected components. Queries are independent of each other.

Input

The first line contains three space-separated integers $n, m, x$.

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

The next $n-1$ lines each contain two space-separated integers $x, y$, representing an edge.

The next line contains $x+1$ integers representing $A_0$ to $A_x$.

The next $m$ lines each contain two space-separated integers $l, r$, representing a query.

Output

Output $m$ lines, each containing the answer for the corresponding query.

Examples

Input 1

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

Output 1

1
4
4

Subtasks

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

Note: This problem uses bundled testing. You will only receive points for a subtask if you pass all test cases within that subtask.

For $1\%$ of the data, the input is the sample case.

For another $9\%$ of the data, $n, m \leq 200$.

For another $19\%$ of the data, $n, m \leq 2000$.

For another $19\%$ of the data, $x \leq 10$.

For $100\%$ of the data, $1 \leq n, m \leq 10^5$, $1 \leq x, A_i \leq 10^4$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.