14547 - Take leaves   

Description

Elephants enjoy taking leaves from trees to eat. At the i-th node of the tree, there are vi​ leaves.

However, trees in computer science differ from real-world trees, the tree has n nodes and n - 1 edges and is rooted at node 1.

If a node is removed, all nodes beneath it (i.e., its subtree) will also be removed.

The problem involves q queries, and each query provides an integer k, asking how many leaves in total (including the leaves at node k) will be removed if node k is removed.

 

(In this problem, "leaves" are used to represent the value of a node, not the actual leaf nodes as defined in a tree structure.)

Input

The first line contains two integers, n and q.

2 ≤ nq ≤ 1000 (Testcases 1 ~ 2)

2 ≤ nq ≤ 2 * 10(Testcases 3 ~ 5)


The second line contain n integers vi, representing the leaves on i-th node.

vi ≤ 1000

 

The following n - 1 lines each line contain two integers u and v, representing that u and v is connected.

u, v n

It is guaranteed that the graph is a tree.

 

The following q lines each line contain a integer k, answer the sum of leaves on the k-th node's subtree.

1 ≤ k ≤ n

Output

For each query, output the answer of sum of leaves on the k-th node's subtree, followed by a new line character '\n'.

Sample Input  Download

Sample Output  Download

Tags




Discuss