import bisect

import sys

sys.setrecursionlimit(10**9)



N = int(input())

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



tree = [[] for i in range(N)]

for i in range(N-1):

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

  tree[u-1].append(v-1); tree[v-1].append(u-1)





ans = [0] * N

ans[0] = 1

INF = 10**10

dp = [INF] * N

dp[0] = A[0]

stack = []

n_stack = []

def dfs(node, par, n):

  global ans

  global dp

  global stack

  children = tree[node]

  for child in children:

    if child == par:

      continue

    num = A[child]

    idx = bisect.bisect_left(dp, num)

    stack.append([idx, dp[idx]])

    n_stack.append(n)

    dp[idx] = num

    n = max(n, idx + 1)

    ans[child] = n

    dfs(child, node, n)

    # 巻き戻し

    idx, num = stack.pop()

    dp[idx] = num

    n = n_stack.pop()



dfs(0, -1, 1)

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

import bisect

import sys

sys.setrecursionlimit(10**9)



N = int(input())

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



tree = [[] for i in range(N)]

for i in range(N-1):

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

  tree[u-1].append(v-1); tree[v-1].append(u-1)





ans = [0] * N

ans[0] = 1

INF = 10**10

dp = [INF] * N

dp[0] = A[0]

def dfs(node, par, n):

  global ans

  global dp

  children = tree[node]

  for child in children:

    if child == par:

      continue

    num = A[child]

    idx = bisect.bisect_left(dp, num)

    _idx, _num = idx, dp[idx] # 巻き戻し用に退避

    dp[idx] = num

    _n = max(n, idx + 1)

    ans[child] = _n

    dfs(child, node, _n)

    # 巻き戻し

    dp[_idx] = _num



dfs(0, -1, 1)

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

import bisect
import sys

sys.setrecursionlimit(10**9)
N = int(input())
A = list(map(int, input().split()))
tree = [[] for i in range(N)]
for i in range(N - 1):
    u, v = map(int, input().split())
    tree[u - 1].append(v - 1)
    tree[v - 1].append(u - 1)
ans = [0] * N
ans[0] = 1
INF = 10**10
dp = [INF] * N
dp[0] = A[0]
stack = []
n_stack = []


def dfs(node, par, n):
    global ans
    global dp
    global stack
    children = tree[node]
    for child in children:
        if child == par:
            continue
        num = A[child]
        idx = bisect.bisect_left(dp, num)
        stack.append([idx, dp[idx]])
        n_stack.append(n)
        dp[idx] = num
        n = max(n, idx + 1)
        ans[child] = n
        dfs(child, node, n)
        # 巻き戻し
        idx, num = stack.pop()
        dp[idx] = num
        n = n_stack.pop()


dfs(0, -1, 1)
print(*ans, sep="\n")

import bisect
import sys

sys.setrecursionlimit(10**9)
N = int(input())
A = list(map(int, input().split()))
tree = [[] for i in range(N)]
for i in range(N - 1):
    u, v = map(int, input().split())
    tree[u - 1].append(v - 1)
    tree[v - 1].append(u - 1)
ans = [0] * N
ans[0] = 1
INF = 10**10
dp = [INF] * N
dp[0] = A[0]


def dfs(node, par, n):
    global ans
    global dp
    children = tree[node]
    for child in children:
        if child == par:
            continue
        num = A[child]
        idx = bisect.bisect_left(dp, num)
        _idx, _num = idx, dp[idx]  # 巻き戻し用に退避
        dp[idx] = num
        _n = max(n, idx + 1)
        ans[child] = _n
        dfs(child, node, _n)
        # 巻き戻し
        dp[_idx] = _num


dfs(0, -1, 1)
print(*ans, sep="\n")

-stack = [] -n_stack = [] -    global stack -        stack.append([idx, dp[idx]]) -        n_stack.append(n) +        _idx, _num = idx, dp[idx]  # 巻き戻し用に退避 -        n = max(n, idx + 1) -        ans[child] = n -        dfs(child, node, n) +        _n = max(n, idx + 1) +        ans[child] = _n +        dfs(child, node, _n) -        idx, num = stack.pop() -        dp[idx] = num -        n = n_stack.pop() +        dp[_idx] = _num