import sys

sys.setrecursionlimit(10 ** 9)



from bisect import bisect_left



N = int(input())

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



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



for _ in range(N - 1):

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

    u -= 1

    v -= 1

    G[u].append(v)

    G[v].append(u)





root = 0



ans = [0] * N

check = [False] * N

check[root] = True



memo = [None] * N



INF = 10 ** 10

dp = [INF] * N



def dfs(x):

    tmp = bisect_left(dp, A[x])

    memo[x] = (tmp, dp[tmp])

    dp[tmp] = A[x]

    ans[x] = bisect_left(dp, INF)

    for next_ in G[x]:

        if check[next_]:

            continue

        check[next_] = True

        dfs(next_)

    j, a = memo[x]

    dp[j] = a



dfs(root)



print (*ans, sep = '\n')



import sys

sys.setrecursionlimit(10 ** 9)



from bisect import bisect_left



N = int(input())

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



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



for _ in range(N - 1):

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

    u -= 1

    v -= 1

    G[u].append(v)

    G[v].append(u)



root = 0

stack = [root]

visited = set()

visited.add(root)

done = set()

vs = []



ans = [0] * N

memo = [None] * N

memo[root] = (0, A[root])



INF = 10 ** 10

dp = [INF] * N



while stack:

    now_ = stack[-1]

    if now_ in done:

        j, a = memo[now_]

        dp[j] = a

        stack.pop()

        vs.append(now_)

    else:

        for next_ in G[now_][::-1]:

            if next_ in visited:

                continue

            visited.add(next_)

            stack.append(next_)

        done.add(now_)



        tmp = bisect_left(dp, A[now_])

        memo[now_] = (tmp, dp[tmp])

        dp[tmp] = A[now_]

        ans[now_] = bisect_left(dp, INF)



# print (vs)

print (*ans, sep = '\n')

import sys

sys.setrecursionlimit(10**9)
from bisect import bisect_left

N = int(input())
A = list(map(int, input().split()))
G = [[] for _ in range(N)]
for _ in range(N - 1):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    G[u].append(v)
    G[v].append(u)
root = 0
ans = [0] * N
check = [False] * N
check[root] = True
memo = [None] * N
INF = 10**10
dp = [INF] * N


def dfs(x):
    tmp = bisect_left(dp, A[x])
    memo[x] = (tmp, dp[tmp])
    dp[tmp] = A[x]
    ans[x] = bisect_left(dp, INF)
    for next_ in G[x]:
        if check[next_]:
            continue
        check[next_] = True
        dfs(next_)
    j, a = memo[x]
    dp[j] = a


dfs(root)
print(*ans, sep="\n")

import sys

sys.setrecursionlimit(10**9)
from bisect import bisect_left

N = int(input())
A = list(map(int, input().split()))
G = [[] for _ in range(N)]
for _ in range(N - 1):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    G[u].append(v)
    G[v].append(u)
root = 0
stack = [root]
visited = set()
visited.add(root)
done = set()
vs = []
ans = [0] * N
memo = [None] * N
memo[root] = (0, A[root])
INF = 10**10
dp = [INF] * N
while stack:
    now_ = stack[-1]
    if now_ in done:
        j, a = memo[now_]
        dp[j] = a
        stack.pop()
        vs.append(now_)
    else:
        for next_ in G[now_][::-1]:
            if next_ in visited:
                continue
            visited.add(next_)
            stack.append(next_)
        done.add(now_)
        tmp = bisect_left(dp, A[now_])
        memo[now_] = (tmp, dp[tmp])
        dp[tmp] = A[now_]
        ans[now_] = bisect_left(dp, INF)
# print (vs)
print(*ans, sep="\n")

+stack = [root] +visited = set() +visited.add(root) +done = set() +vs = [] -check = [False] * N -check[root] = True +memo[root] = (0, A[root]) - - -def dfs(x): -    tmp = bisect_left(dp, A[x]) -    memo[x] = (tmp, dp[tmp]) -    dp[tmp] = A[x] -    ans[x] = bisect_left(dp, INF) -    for next_ in G[x]: -        if check[next_]: -            continue -        check[next_] = True -        dfs(next_) -    j, a = memo[x] -    dp[j] = a - - -dfs(root) +while stack: +    now_ = stack[-1] +    if now_ in done: +        j, a = memo[now_] +        dp[j] = a +        stack.pop() +        vs.append(now_) +    else: +        for next_ in G[now_][::-1]: +            if next_ in visited: +                continue +            visited.add(next_) +            stack.append(next_) +        done.add(now_) +        tmp = bisect_left(dp, A[now_]) +        memo[now_] = (tmp, dp[tmp]) +        dp[tmp] = A[now_] +        ans[now_] = bisect_left(dp, INF) +# print (vs)