CSES - Ant colony
  • Time limit: 2.00 s
  • Memory limit: 128 MB

The ants are scavenging an abandoned ant hill in search of food. The ant hill has nn chambers and n1n-1 corridors connecting them. We know that each chamber can be reached via a unique path from every other chamber. In other words, the chambers and the corridors form a tree.

There is an entrance to the ant hill in every chamber with only one corridor leading into (or out of) it. At each entry, there are gg groups of m1,m2,,mgm_1, m_2, \ldots, m_g ants respectively. These groups will enter the ant hill one after another, each successive group entering once there are no ants inside. Inside the hill, the ants explore it in the following way:

  • Upon entering a chamber with dd outgoing corridors yet unexplored by the group, the group divides into dd groups of equal size. Each newly created group follows one of the dd corridors. If d=0d=0, then the group exits the ant hill.
  • If the ants cannot divide into equal groups, then the stronger ants eat the weaker until a perfect division is possible. Note that such a division is always possible since eventually the number of ants drops down to zero. Nothing can stop the ants from allowing divisibility - in particular, an ant can eat itself, and the last one remaining will do so if the group is smaller than dd.

The following figure depicts mm ants upon entering a chamber with three outgoing unexplored corridors, dividing themselves into three (equal) groups of m/3\lfloor m/3 \rfloor ants each.

A hungry anteater dug into one of the corridors and can now eat all the ants passing through it. However, just like the ants, the anteater is very picky when it comes to numbers. It will devour a passing group if and only if it consists of exactly kk ants. We want to know how many ants the anteater will eat.

Input

The first line of the standard input contains three integers nn, gg, kk, separated by single spaces. These specify the number of chambers, the number of ant groups and the number of ants the anteater devours at once. The chambers are numbered from 11 to nn.

The second line contains gg integers m1,m2,,mgm_1, m_2, \ldots, m_g, separated by single spaces, where mim_i gives the number of ants in the ii-th group at every entrance to the ant hill. The n1n-1 lines that follow describe the corridors within the ant hill; the ii-th such line contains two integers ai,bia_i, b_i, separated by a single space, that indicate that the chambers no. aia_i and bib_i are linked by a corridor. The anteater has dug into the corridor that appears first on input.

Output

Your program should print to the standard output a single line containing a single integer: the number of ants eaten by the anteater.

Constraints

  • 2n,g1062 \le n, g \le 10^6
  • 1k1091 \le k \le 10^9
  • 1mi1091 \le m_i \le 10^9
  • 1ai,bin1 \le a_i, b_i \le n

Example

For the input data:

7 5 3
3 4 1 9 11
1 2
1 4
4 3
4 5
4 6
6 7

the correct result is:

21

Explanation: Next to each of the chambers no. 2, 3, 5, and 7, there are 5 groups of ants. The anteater will eat 3 ants from the first group that starts its exploration at chamber no. 2 and 3 ants from both the fourth and the fifth group that start their exploration at the chamber no. 3, 5, or 7.

Task author: Jacek Tomasiewicz.