import bisect

import sys

sys.setrecursionlimit(10**7)



def dfs(v):

    pos=bisect.bisect_left(dp,arr[v])

    changes.append((pos,dp[pos]))

    dp[pos]=arr[v]

    ans[v]=bisect.bisect_left(dp,10**18)

    for u in g[v]:

        if checked[u]==0:

            checked[u]=1

            dfs(u)

    pos,val=changes.pop()

    dp[pos]=val





n=int(eval(input()))

arr=[0]+list(map(int,input().split()))

g=[[] for _ in range(n+1)]

for _ in range(n-1):

    a,b=list(map(int,input().split()))

    g[a].append(b)

    g[b].append(a)

ans=[0]*(n+1)

checked=[0]*(n+1)

checked[1]=1

dp=[10**18 for _ in range(n+1)]

changes=[]

dfs(1)

for i in range(1,n+1):

    print((ans[i]))
from collections import deque

import bisect



N=int(eval(input()))

A=list(map(int,input().split()))

ans=[0]*N

Edge=[[] for _ in range(N)]

loute=[str(0)]*N

for i in range(N-1):

    u,v=list(map(int,input().split()))

    Edge[u-1].append(v-1)

    Edge[v-1].append(u-1)

  

tmp=deque(str(0))

CHN=deque()

LIS=[10**18]*N

label=[False]*N

while tmp:

    T0=int(tmp[-1])

    if label[T0]:

        tmp.pop()

        pos,Val=CHN.pop()

        LIS[pos]=Val

        continue



    pos=bisect.bisect_left(LIS,A[T0])

    CHN.append((pos,LIS[pos]))

    LIS[pos]=A[T0]

    ans[T0]=bisect.bisect_left(LIS,10**18)



    if Edge[T0]:

        for i in Edge[T0]:

            if label[i]==False:

                tmp.append(i)

        label[T0]=True

    else:

        label[T0]=True

    

for i in range(N):

    print((ans[i]))
import bisect
import sys

sys.setrecursionlimit(10**7)


def dfs(v):
    pos = bisect.bisect_left(dp, arr[v])
    changes.append((pos, dp[pos]))
    dp[pos] = arr[v]
    ans[v] = bisect.bisect_left(dp, 10**18)
    for u in g[v]:
        if checked[u] == 0:
            checked[u] = 1
            dfs(u)
    pos, val = changes.pop()
    dp[pos] = val


n = int(eval(input()))
arr = [0] + list(map(int, input().split()))
g = [[] for _ in range(n + 1)]
for _ in range(n - 1):
    a, b = list(map(int, input().split()))
    g[a].append(b)
    g[b].append(a)
ans = [0] * (n + 1)
checked = [0] * (n + 1)
checked[1] = 1
dp = [10**18 for _ in range(n + 1)]
changes = []
dfs(1)
for i in range(1, n + 1):
    print((ans[i]))

from collections import deque
import bisect

N = int(eval(input()))
A = list(map(int, input().split()))
ans = [0] * N
Edge = [[] for _ in range(N)]
loute = [str(0)] * N
for i in range(N - 1):
    u, v = list(map(int, input().split()))
    Edge[u - 1].append(v - 1)
    Edge[v - 1].append(u - 1)
tmp = deque(str(0))
CHN = deque()
LIS = [10**18] * N
label = [False] * N
while tmp:
    T0 = int(tmp[-1])
    if label[T0]:
        tmp.pop()
        pos, Val = CHN.pop()
        LIS[pos] = Val
        continue
    pos = bisect.bisect_left(LIS, A[T0])
    CHN.append((pos, LIS[pos]))
    LIS[pos] = A[T0]
    ans[T0] = bisect.bisect_left(LIS, 10**18)
    if Edge[T0]:
        for i in Edge[T0]:
            if label[i] == False:
                tmp.append(i)
        label[T0] = True
    else:
        label[T0] = True
for i in range(N):
    print((ans[i]))

+from collections import deque -import sys -sys.setrecursionlimit(10**7) - - -def dfs(v): -    pos = bisect.bisect_left(dp, arr[v]) -    changes.append((pos, dp[pos])) -    dp[pos] = arr[v] -    ans[v] = bisect.bisect_left(dp, 10**18) -    for u in g[v]: -        if checked[u] == 0: -            checked[u] = 1 -            dfs(u) -    pos, val = changes.pop() -    dp[pos] = val - - -n = int(eval(input())) -arr = [0] + list(map(int, input().split())) -g = [[] for _ in range(n + 1)] -for _ in range(n - 1): -    a, b = list(map(int, input().split())) -    g[a].append(b) -    g[b].append(a) -ans = [0] * (n + 1) -checked = [0] * (n + 1) -checked[1] = 1 -dp = [10**18 for _ in range(n + 1)] -changes = [] -dfs(1) -for i in range(1, n + 1): +N = int(eval(input())) +A = list(map(int, input().split())) +ans = [0] * N +Edge = [[] for _ in range(N)] +loute = [str(0)] * N +for i in range(N - 1): +    u, v = list(map(int, input().split())) +    Edge[u - 1].append(v - 1) +    Edge[v - 1].append(u - 1) +tmp = deque(str(0)) +CHN = deque() +LIS = [10**18] * N +label = [False] * N +while tmp: +    T0 = int(tmp[-1]) +    if label[T0]: +        tmp.pop() +        pos, Val = CHN.pop() +        LIS[pos] = Val +        continue +    pos = bisect.bisect_left(LIS, A[T0]) +    CHN.append((pos, LIS[pos])) +    LIS[pos] = A[T0] +    ans[T0] = bisect.bisect_left(LIS, 10**18) +    if Edge[T0]: +        for i in Edge[T0]: +            if label[i] == False: +                tmp.append(i) +        label[T0] = True +    else: +        label[T0] = True +for i in range(N):