Problem:
You have a Tree with N nodes rooted at 1 where ith node is associated with a value Ai. Now consider the following definition:
K-Tuple: A tuple of K+1 nodes (X1,X2,X3,…,XK+1) is a K-Tuple if:
1.) Xi is an ancestor of Xi+1∀1≤i≤K
2.) AXi>AXi+1∀1≤i≤K
Calculate the number of K-Tuples in the tree.
Input:
First line contains two integers N and K, the number of nodes in the tree and the value for the Tuple type you need to calculate answer for.
Next line contains N space separated integers where the ith integer denotes the value Ai.
Next N−1 lines contains X and Y denoting that there is an edge between them.
Output:
Output a single integer mod (109+7) denoting the number of K-tuples in the tree.
Constraints:
1≤N,Ai≤100000
1≤X,Y≤N
1≤K≤20
There are 4 2-Tuples: (1,2,4), (1,2,5), (1,3,6), (1,3,7).