#Lutece1550. L0ngest Path
L0ngest Path
Migrated from Lutece 1550 L0ngest Path
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
A Yggdrazil blooming on the cover of the poetry. We must solve the mystery to open it for the forbidden knowledge.
Each node in the Yggdrazil had a magic number , and there are branches connected some pair of nodes.
After checking Yggdrazil, we find there is exactly one simple path between each pair of nodes.
If we can find a longest simple path in the Yggdrazil whose differ between the maximum magic number and the minimum magic number in the path is not greater than , we can open the old poetry and master the forbidden knowledge.
The length of a path is the number of nodes on it.
Input
The first line contains two integers and , which mean the number of nodes in Yggdrazil, and the maximum differ limit.
The second line contains integers , which mean the magic number of nodes , , ..., .
For the next lines, each line contains two integers , , mean there is a branch connected node and node .
, , .
Output
An integer denote the length of the longest path in Yggdrazil which can help us open the old poetry.
Samples
Note
The longest path which satisfies the limit is .
Resources
The 15th UESTC Programming Contest Preliminary