#P10935. [2015杭电多校]Crazy Bobo

[2015杭电多校]Crazy Bobo

Crazy Bobo

Problem Description

Bobo has a tree,whose vertices are conveniently labeled by 1,2,...,n.Each node has a weight wiw_i. All the weights are distrinct. A set with m nodes v1,v2,...,vm{v_1,v_2,...,v_m} is a Bobo Set if:

  • The subgraph of his tree induced by this set is connected.
  • After we sort these nodes in set by their weights in ascending order,we get u1,u2,...,um{u_1,u_2,...,u_m},(that is,wui<wui+1w_{u_i} < w_{u_{i+1}} for i from 1 to m-1).For any node xx in the path from uiu_i to ui+1u_{i+1}(excluding uiu_i and ui+1u_{i+1}),should satisfy wx<wuiw_x < w_{u_i}. Your task is to find the maximum size of Bobo Set in a given tree.

Input

The input consists of several tests. For each tests: The first line contains a integer n (1n5000001 \leq n \leq 500000). Then following a line contains n integers w1,w2,...,wnw_1,w_2,...,w_n (1wi1091 \leq w_i \leq 10^9,all the wiw_i is distrinct).Each of the following n-1 lines contain 2 integers aia_i and bib_i,denoting an edge between vertices aia_i and bib_i (1ai,bin1 \leq a_i,b_i \leq n). The sum of n is not bigger than 800000.

Output

For each test output one line contains a integer,denoting the maximum size of Bobo Set.

Sample Input

7
3 30 350 100 200 300 400
1 2
2 3
3 4
4 5
5 6
6 7

Sample Output

5

Author

ZSTU

Source

2015 Multi-University Training Contest 3