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 = []

def dfs(node, par):

  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]])

    dp[idx] = num

    ans[child] = bisect.bisect_left(dp, INF)

    dfs(child, node)

    # 巻き戻し

    idx, num = stack.pop()

    dp[idx] = num



dfs(0, -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 = []

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]])

    dp[idx] = num

    ans[child] = max(n, idx+1)

    # ans[child] = bisect.bisect_left(dp, INF)

    dfs(child, node, max(n, idx+1))

    # 巻き戻し

    idx, num = stack.pop()

    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 = []


def dfs(node, par):
    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]])
        dp[idx] = num
        ans[child] = bisect.bisect_left(dp, INF)
        dfs(child, node)
        # 巻き戻し
        idx, num = stack.pop()
        dp[idx] = num


dfs(0, -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 = []


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]])
        dp[idx] = num
        ans[child] = max(n, idx + 1)
        # ans[child] = bisect.bisect_left(dp, INF)
        dfs(child, node, max(n, idx + 1))
        # 巻き戻し
        idx, num = stack.pop()
        dp[idx] = num


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

-def dfs(node, par): +def dfs(node, par, n): -        ans[child] = bisect.bisect_left(dp, INF) -        dfs(child, node) +        ans[child] = max(n, idx + 1) +        # ans[child] = bisect.bisect_left(dp, INF) +        dfs(child, node, max(n, idx + 1)) -dfs(0, -1) +dfs(0, -1, 1)