import bisect





n = int(eval(input()))

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



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

for _ in range(n-1):

    from_, to = list(map(int, input().split()))

    edges[from_].append(to)

    edges[to].append(from_)





DP = [10**9+7] * (n+1)

limit = 10**9 + 1

DP[0] = 0

olds = [None] * (n+1)

ans = [0] * n



todo = [1]

while todo:

    node = todo.pop()

    if node > 0:

        num = A[node-1]

        update_idx = bisect.bisect_left(DP, num)

        old = DP[update_idx]

        olds[node] = (old, update_idx)

        DP[update_idx] = num

        lis = bisect.bisect_left(DP, limit) - 1

        ans[node-1] = lis



        todo.append(-node)

        for to in edges[node]:

            if ans[to-1]:

                continue

            todo.append(to)



    else:

        node = -node

        old, update_idx = olds[node]

        DP[update_idx] = old



for res in ans:

    print(res)

import bisect

import sys

input = sys.stdin.readline





n = int(eval(input()))

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



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

for _ in range(n-1):

    from_, to = list(map(int, input().split()))

    edges[from_].append(to)

    edges[to].append(from_)





DP = [10**9+7] * (n+1)

limit = 10**9 + 1

DP[0] = 0

olds = [None] * (n+1)

ans = [0] * n



todo = [1]

while todo:

    node = todo.pop()

    if node > 0:

        num = A[node-1]

        update_idx = bisect.bisect_left(DP, num)

        old = DP[update_idx]

        olds[node] = (old, update_idx)

        DP[update_idx] = num

        lis = bisect.bisect_left(DP, limit) - 1

        ans[node-1] = lis



        todo.append(-node)

        for to in edges[node]:

            if ans[to-1]:

                continue

            todo.append(to)



    else:

        node = -node

        old, update_idx = olds[node]

        DP[update_idx] = old



for res in ans:

    print(res)

import bisect

n = int(eval(input()))
A = list(map(int, input().split()))
edges = [[] for _ in range(n + 1)]
for _ in range(n - 1):
    from_, to = list(map(int, input().split()))
    edges[from_].append(to)
    edges[to].append(from_)
DP = [10**9 + 7] * (n + 1)
limit = 10**9 + 1
DP[0] = 0
olds = [None] * (n + 1)
ans = [0] * n
todo = [1]
while todo:
    node = todo.pop()
    if node > 0:
        num = A[node - 1]
        update_idx = bisect.bisect_left(DP, num)
        old = DP[update_idx]
        olds[node] = (old, update_idx)
        DP[update_idx] = num
        lis = bisect.bisect_left(DP, limit) - 1
        ans[node - 1] = lis
        todo.append(-node)
        for to in edges[node]:
            if ans[to - 1]:
                continue
            todo.append(to)
    else:
        node = -node
        old, update_idx = olds[node]
        DP[update_idx] = old
for res in ans:
    print(res)

import bisect
import sys

input = sys.stdin.readline
n = int(eval(input()))
A = list(map(int, input().split()))
edges = [[] for _ in range(n + 1)]
for _ in range(n - 1):
    from_, to = list(map(int, input().split()))
    edges[from_].append(to)
    edges[to].append(from_)
DP = [10**9 + 7] * (n + 1)
limit = 10**9 + 1
DP[0] = 0
olds = [None] * (n + 1)
ans = [0] * n
todo = [1]
while todo:
    node = todo.pop()
    if node > 0:
        num = A[node - 1]
        update_idx = bisect.bisect_left(DP, num)
        old = DP[update_idx]
        olds[node] = (old, update_idx)
        DP[update_idx] = num
        lis = bisect.bisect_left(DP, limit) - 1
        ans[node - 1] = lis
        todo.append(-node)
        for to in edges[node]:
            if ans[to - 1]:
                continue
            todo.append(to)
    else:
        node = -node
        old, update_idx = olds[node]
        DP[update_idx] = old
for res in ans:
    print(res)

+import sys +input = sys.stdin.readline