You have a lemon tree containing lemons connected with
branches. Each lemon has a value. We call the floor of the arithmetic mean of the values on the path from
to
the relation between lemon
and lemon
. Tommy can only eat the two lemons if their relation is not greater than
; otherwise, Tommy will have syncope. Please help Tommy determine how many pairs of lemons he can eat.
Input Specification
The first line contains two integers,
and
.
The next line contains integers. The
integer,
, represents the value of
lemon.
The next lines will each contain two integers,
and
, indicating that there is a branch between lemon
and
.
Output Specification
Output the number of pairs of lemons Tommy can eat.
Constraints
Subtask | Points | Additional constraints |
---|---|---|
No additional constraints. |
Sample Input 1
6 2
5 3 4 1 10 1
1 2
1 3
1 4
3 5
3 6
Sample Output 1
2
Explanation for Sample 1
The two pairs of lemons Tommy can eat are and
.
Sample Input 2
5 3
10 3 2 4 5
1 2
1 3
2 4
3 5
Sample Output 2
2
Comments