import sys

from bisect import bisect_left

def main():

    sys.setrecursionlimit(202020)

    N = int(eval(input()))

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

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

    for _ in range(N-1):

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

        G[u].append(v)

        G[v].append(u)

    L = [A[1]]

    Ans = [0] * (N+1)

    def dfs(v):

        Ans[v] = len(L)

        for u in G[v]:

            G[u].remove(v)

            Au = A[u]

            if Au > L[-1]:

                L.append(Au)

                dfs(u)

                del L[-1]

            else:

                idx = bisect_left(L, Au)

                old = L[idx]

                L[idx] = Au

                dfs(u)

                L[idx] = old

    dfs(1)

    print(("\n".join(map(str, Ans[1:]))))



main()

def numba_compile(numba_config):

    import os, sys

    if sys.argv[-1] == "ONLINE_JUDGE":

        from numba import njit

        from numba.pycc import CC

        cc = CC("my_module")

        for func, signature in numba_config:

            globals()[func.__name__] = njit(signature)(func)

            cc.export(func.__name__, signature)(func)

        cc.compile()

        exit()

    elif os.name == "posix":

        exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")

        for func, _ in numba_config:

            globals()[func.__name__] = vars()[func.__name__]

    else:

        from numba import njit

        for func, signature in numba_config:

            globals()[func.__name__] = njit(signature, cache=True)(func)

        print("compiled!", file=sys.stderr)





import sys

import numpy as np



def solve(N, A, UV):

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

    for i in range(N-1):

        u, v = UV[i]

        G[u].append(v)

        G[v].append(u)

    L = [A[0]]

    Ans = np.zeros(N, dtype=np.int64)

    stack = [(0, 0, 0, -1, -1)]  # 頂点、状態、見ている子のインデックス、行った行動*2

    while stack:

        v, state, idx_Gv, idx_L, old = stack.pop()

        if state == 0:

            Ans[v] = len(L)

        if state == 2:

            if idx_L == -1:

                del L[-1]

            else:

                L[idx_L] = old

        Gv = G[v]

        if len(Gv) == idx_Gv:

            continue

        u = Gv[idx_Gv]

        G[u].remove(v)

        Au = A[u]

        if Au > L[-1]:

            L.append(Au)

            stack.append((v, 2, idx_Gv + 1, -1, -1))

            stack.append((u, 0, 0, -1, -1))

            continue

        else:

            idx_L = np.searchsorted(L, Au)

            old = L[idx_L]

            L[idx_L] = Au

            stack.append((v, 2, idx_Gv + 1, idx_L, old))

            stack.append((u, 0, 0, -1, -1))

            continue

    return Ans



numba_compile([

    [solve, "i8[:](i8,i8[:],i8[:,:])"]

])



def main():

    input = sys.stdin.buffer.readline

    N = int(input())

    A = np.array(input().split(), dtype=np.int64)

    UV = np.array(sys.stdin.buffer.read().split(), dtype=np.int64).reshape(N-1, 2) - 1

    Ans = solve(N, A, UV)

    print("\n".join(map(str, Ans.tolist())))



main()

import sys
from bisect import bisect_left


def main():
    sys.setrecursionlimit(202020)
    N = int(eval(input()))
    A = [0] + list(map(int, input().split()))
    G = [[] for _ in range(N + 1)]
    for _ in range(N - 1):
        u, v = list(map(int, input().split()))
        G[u].append(v)
        G[v].append(u)
    L = [A[1]]
    Ans = [0] * (N + 1)

    def dfs(v):
        Ans[v] = len(L)
        for u in G[v]:
            G[u].remove(v)
            Au = A[u]
            if Au > L[-1]:
                L.append(Au)
                dfs(u)
                del L[-1]
            else:
                idx = bisect_left(L, Au)
                old = L[idx]
                L[idx] = Au
                dfs(u)
                L[idx] = old

    dfs(1)
    print(("\n".join(map(str, Ans[1:]))))


main()

def numba_compile(numba_config):
    import os, sys

    if sys.argv[-1] == "ONLINE_JUDGE":
        from numba import njit
        from numba.pycc import CC

        cc = CC("my_module")
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature)(func)
            cc.export(func.__name__, signature)(func)
        cc.compile()
        exit()
    elif os.name == "posix":
        exec(
            f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}"
        )
        for func, _ in numba_config:
            globals()[func.__name__] = vars()[func.__name__]
    else:
        from numba import njit

        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature, cache=True)(func)
        print("compiled!", file=sys.stderr)


import sys
import numpy as np


def solve(N, A, UV):
    G = [[0] * 0 for _ in range(N)]
    for i in range(N - 1):
        u, v = UV[i]
        G[u].append(v)
        G[v].append(u)
    L = [A[0]]
    Ans = np.zeros(N, dtype=np.int64)
    stack = [(0, 0, 0, -1, -1)]  # 頂点、状態、見ている子のインデックス、行った行動*2
    while stack:
        v, state, idx_Gv, idx_L, old = stack.pop()
        if state == 0:
            Ans[v] = len(L)
        if state == 2:
            if idx_L == -1:
                del L[-1]
            else:
                L[idx_L] = old
        Gv = G[v]
        if len(Gv) == idx_Gv:
            continue
        u = Gv[idx_Gv]
        G[u].remove(v)
        Au = A[u]
        if Au > L[-1]:
            L.append(Au)
            stack.append((v, 2, idx_Gv + 1, -1, -1))
            stack.append((u, 0, 0, -1, -1))
            continue
        else:
            idx_L = np.searchsorted(L, Au)
            old = L[idx_L]
            L[idx_L] = Au
            stack.append((v, 2, idx_Gv + 1, idx_L, old))
            stack.append((u, 0, 0, -1, -1))
            continue
    return Ans


numba_compile([[solve, "i8[:](i8,i8[:],i8[:,:])"]])


def main():
    input = sys.stdin.buffer.readline
    N = int(input())
    A = np.array(input().split(), dtype=np.int64)
    UV = np.array(sys.stdin.buffer.read().split(), dtype=np.int64).reshape(N - 1, 2) - 1
    Ans = solve(N, A, UV)
    print("\n".join(map(str, Ans.tolist())))


main()

+def numba_compile(numba_config): +    import os, sys + +    if sys.argv[-1] == "ONLINE_JUDGE": +        from numba import njit +        from numba.pycc import CC + +        cc = CC("my_module") +        for func, signature in numba_config: +            globals()[func.__name__] = njit(signature)(func) +            cc.export(func.__name__, signature)(func) +        cc.compile() +        exit() +    elif os.name == "posix": +        exec( +            f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}" +        ) +        for func, _ in numba_config: +            globals()[func.__name__] = vars()[func.__name__] +    else: +        from numba import njit + +        for func, signature in numba_config: +            globals()[func.__name__] = njit(signature, cache=True)(func) +        print("compiled!", file=sys.stderr) + + -from bisect import bisect_left +import numpy as np + + +def solve(N, A, UV): +    G = [[0] * 0 for _ in range(N)] +    for i in range(N - 1): +        u, v = UV[i] +        G[u].append(v) +        G[v].append(u) +    L = [A[0]] +    Ans = np.zeros(N, dtype=np.int64) +    stack = [(0, 0, 0, -1, -1)]  # 頂点、状態、見ている子のインデックス、行った行動*2 +    while stack: +        v, state, idx_Gv, idx_L, old = stack.pop() +        if state == 0: +            Ans[v] = len(L) +        if state == 2: +            if idx_L == -1: +                del L[-1] +            else: +                L[idx_L] = old +        Gv = G[v] +        if len(Gv) == idx_Gv: +            continue +        u = Gv[idx_Gv] +        G[u].remove(v) +        Au = A[u] +        if Au > L[-1]: +            L.append(Au) +            stack.append((v, 2, idx_Gv + 1, -1, -1)) +            stack.append((u, 0, 0, -1, -1)) +            continue +        else: +            idx_L = np.searchsorted(L, Au) +            old = L[idx_L] +            L[idx_L] = Au +            stack.append((v, 2, idx_Gv + 1, idx_L, old)) +            stack.append((u, 0, 0, -1, -1)) +            continue +    return Ans + + +numba_compile([[solve, "i8[:](i8,i8[:],i8[:,:])"]]) -    sys.setrecursionlimit(202020) -    N = int(eval(input())) -    A = [0] + list(map(int, input().split())) -    G = [[] for _ in range(N + 1)] -    for _ in range(N - 1): -        u, v = list(map(int, input().split())) -        G[u].append(v) -        G[v].append(u) -    L = [A[1]] -    Ans = [0] * (N + 1) - -    def dfs(v): -        Ans[v] = len(L) -        for u in G[v]: -            G[u].remove(v) -            Au = A[u] -            if Au > L[-1]: -                L.append(Au) -                dfs(u) -                del L[-1] -            else: -                idx = bisect_left(L, Au) -                old = L[idx] -                L[idx] = Au -                dfs(u) -                L[idx] = old - -    dfs(1) -    print(("\n".join(map(str, Ans[1:])))) +    input = sys.stdin.buffer.readline +    N = int(input()) +    A = np.array(input().split(), dtype=np.int64) +    UV = np.array(sys.stdin.buffer.read().split(), dtype=np.int64).reshape(N - 1, 2) - 1 +    Ans = solve(N, A, UV) +    print("\n".join(map(str, Ans.tolist())))