#ABC165F. [ABC165F] LIS on Tree

[ABC165F] LIS on Tree

Score : 600600 points

Problem Statement

We have a tree with NN vertices, whose ii-th edge connects Vertex uiu_i and Vertex viv_i. Vertex ii has an integer aia_i written on it. For every integer kk from 11 through NN, solve the following problem:

  • We will make a sequence by lining up the integers written on the vertices along the shortest path from Vertex 11 to Vertex kk, in the order they appear. Find the length of the longest increasing subsequence of this sequence.

Here, the longest increasing subsequence of a sequence AA of length LL is the subsequence Ai1,Ai2,...,AiMA_{i_1} , A_{i_2} , ... , A_{i_M} with the greatest possible value of MM such that 1i1<i2<...<iML1 \leq i_1 < i_2 < ... < i_M \leq L and Ai1<Ai2<...<AiMA_{i_1} < A_{i_2} < ... < A_{i_M}.

Constraints

  • 2N2×1052 \leq N \leq 2 \times 10^5
  • 1ai1091 \leq a_i \leq 10^9
  • 1ui,viN1 \leq u_i , v_i \leq N
  • uiviu_i \neq v_i
  • The given graph is a tree.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

a1a_1 a2a_2 ...... aNa_N

u1u_1 v1v_1

u2u_2 v2v_2

::

uN1u_{N-1} vN1v_{N-1}

Output

Print NN lines. The kk-th line, print the length of the longest increasing subsequence of the sequence obtained from the shortest path from Vertex 11 to Vertex kk.

10
1 2 5 3 4 6 7 3 2 4
1 2
2 3
3 4
4 5
3 6
6 7
1 8
8 9
9 10
1
2
3
3
4
4
5
2
2
3

For example, the sequence AA obtained from the shortest path from Vertex 11 to Vertex 55 is 1,2,5,3,41,2,5,3,4. Its longest increasing subsequence is A1,A2,A4,A5A_1, A_2, A_4, A_5, with the length of 44.