Kirito in Memeland

All submissions for this problem are available.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Memeland is a country consisting of N cities. There are exactly N  1 undirected roads connecting pairs of cities and there is exactly one path between each pair of cities (a path is a sequence of distinct cities where consecutive cities in the sequence are connected by a road).
As the country is located in mountains, cities may be at different heights. The heigh of ith city is a_{i}.
Kirito is going to travel around Memeland. Kirito is an unusual man, thus he wants to travel only interesting routes. He calls a sequence of cities i_{1}, i_{2}, ..., i_{K} an interesting route if:
 no two cities in the sequence are the same: i.e. ij ≠ i_{j'} for any two j ≠ j'.
 cities i_{j} and i_{j+1} are connected by a road for each 1 ≤ j < K.
 the number of indices j with 1 < j < K with a_{ij1} < a_{ij} > a_{ij+1} is at least L and at most R for some given L and R.
Help Kirito count the number of interesting routes in Memeland.
Input
The first line of the input contains an integer T denoting the number of test cases.
The first line of each test case contains one integer N denoting the number of cities in Memeland. The second line of each test case contains two integers: L and R described in the statement.
The third line of each test case contains N integers where ith integer is a_{i}, the height of ith city. The final N  1 lines contain two integers denoting pairs of cities that are connected by roads.
Output
For each test case, output a single line containing one integer denoting amount of interesting routes.
Constraints
 1 ≤ T ≤ 20
 1 ≤ N ≤ 5*10^{4}
 1 ≤ L ≤ R ≤ 10^{7}
 1 ≤ a_{i} ≤ 10^{7}
Subtasks
 Subtask 1: 1 ≤ N ≤ 10^{3}  20 points
 Subtask 2: Original constraints  80 points
Example
Input: 3 3 1 2 1 3 1 1 2 2 3 7 2 2 1 8 2 3 4 8 1 1 2 2 3 3 4 3 5 3 6 6 7 9 1 7 5 1 1 1 1 1 1 1 1 1 2 2 3 1 4 4 5 1 6 6 7 1 8 8 9 Output: 1 1 24
Author:  maestr0 
Tester:  xcwgf666 
Editorial  http://discuss.codechef.com/problems/KIRMEME 
Tags  divideandconq, maestr0, mediumhard, nov16, tree 
Date Added:  4072016 
Time Limit:  1.5 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 