SOLVE

LATER

Final Problem

/

Sumit has successfully completed all the preliminary rounds of CodoHolic event in **Aurora 2K18**. Now, to win this event he has to solve the final problem which is prepared by one of the famous coder Himanshu. The final problem is as follows:

Given a tree with **'N'** nodes and each node has some cost associated with it given by **A _{i}.** Now, sumit has to perform

- Sumit has to permanently delete edge
**e**from the tree. - After deleting the edge
**e**, Sumit has to count and print the total no. of unordered pairs**(u, v)**such that there exits a path from**node u to node v**and the absolute difference, i.e**| Au - Av | ≤ D.**

**Input :**

- First line of input will consists of two integers
**N**and**D**. - Next line will consists of
**N**space separated integers**A**._{1},A_{2},A_{3}...A_{N} - Next N-1 lines will consists of two integers
**u**and**v**. It denotes that**i**edge consists of two nodes^{th}**u and v**. - Next
**N-1**lines will consists of one integer**e**denoting the queries.

**Output :**

- For each query, print the total number of unordered pairs
**(u, v)**such that there exits path from node**u**to node**v**and**| Au - Av | ≤ D**.

**Constraints :**

- 2<=N<=10
^{5} - -10
^{6}<=A_{i}<=10^{6} - 0<=D<=10
^{6}

Explanation

If we remove edge 4, all the required **(u,v)** pairs are **(1,3), (1,5) , (3,4) , (3,5) , (4,5).**

Time Limit:
1.0 sec(s)
for each input file.

Memory Limit:
256 MB

Source Limit:
1024 KB

Initializing Code Editor...