Given a root tree with vertices, where the root is vertex . Each vertex contains an integer.
We build an array using the following recursive procedure:
dfs(v):
write the number in vertex v to the end of array a
choose any order of the children of vertex v
for each child u in the chosen order:
dfs(u)Initially, is called.
Note that the order of children in each vertex can be chosen arbitrarily, so depending on this, the array can be different.
We will call an element a_i a prefix maximum if it is strictly greater than all previous elements of the array. The first element of the array is also considered a prefix maximum.
It is necessary to find the maximum possible number of prefix maxima in the array .
The first line contains the number (1 \le n \le 2 \cdot 10^5) — the number of vertices in the tree.
The second line contains the array (1 \le a_i \le 10^9) — the values written in the vertices.
In the next n-1 lines, two numbers and (1 \le u, v \le n) are given — the edges in the tree.
Output a single number — the maximum possible number of prefix maxima in the array .
Example 1
In the first test case, we have the following tree.
After choosing the most advantageous traversal, we will have the following array [5, 2, 3, 6, 8, 7, 9].
The prefix maxima for this array will be [5, 6, 8, 9].
Subtask ( points): (n \le 10)
Subtask ( points): (a_i \le 10)
Subtask ( points): (v = u-1)
Subtask ( points): (u = 1)
Subtask ( points): (n \le 100)
Subtask ( points): (n \le 500)
Subtask ( points): (n \le 2000)
Subtask ( points): (n \le 75000)
Subtask ( points): No additional constraints