Rj-A small kid in NSIT

0

0 votes
Medium
Problem

Rj is the most innocent and the junior-most student in NSIT.Since he is a child prodigy he was learning tree when he came across an interesting problem.Given a tree with n nodes with each node having some value A[i] i.e. node number i has value A[i]. Given another integer k. Find number of nodes whose value is greater than or equal to atleast k of its ancestors. Tree is rooted at 1

INPUT FORMAT

The first line contains a positive integer n and k.
The second line contains n space separated integers denoting A[i] for i=1 to n.
Next n-1 line contains two space separated integers x and y denoting that there is an edge between node x and y.

Output Format

Output a single integer denoting the answer to the problem.

Constraints

1<=N<=100000
0<=K<=N-1 1<=A[i]<=1000000

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?