#!/usr/bin/python3



import sys

from bisect import bisect_left



sys.setrecursionlimit(1000000)



n = int(eval(input()))

a = [int(i) for i in input().split()]



nbs = [ [] for _ in range(n) ]



for _ in range(n - 1):

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

    nbs[u - 1].append(v - 1)

    nbs[v - 1].append(u - 1)





mlen = [ 0 ] * n

dp = [ float('inf') ] * n



def getmlen(cur, p, ctail):

    for ch in nbs[cur]:

        if ch == p:

            continue



        idx = bisect_left(dp, a[ch])

        ov = dp[idx]



        ntail = max(ctail, idx)

        dp[idx] = a[ch]

        mlen[ch] = ntail + 1

        getmlen(ch, cur, ntail)

        dp[idx] = ov



        



dp[0] = a[0]

mlen[0] = 1

getmlen(0, -1, 0)



for i in range(n):

    print((mlen[i]))

#!/usr/bin/python3



import sys

from bisect import bisect_left



sys.setrecursionlimit(1000000)



n = int(eval(input()))

a = [int(i) for i in input().split()]



nbs = [ [] for _ in range(n) ]



for _ in range(n - 1):

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

    nbs[u - 1].append(v - 1)

    nbs[v - 1].append(u - 1)





mlen = [ 0 ] * n



def getmlen(cur, p):

    for ch in nbs[cur]:

        if ch == p:

            continue



        if a[ch] > dp[-1]:

            dp.append(a[ch])

            mlen[ch] = len(dp)

            getmlen(ch, cur)

            dp.pop(-1)

        else:

            idx = bisect_left(dp, a[ch])

            ov = dp[idx]

            dp[idx] = a[ch]

            mlen[ch] = len(dp)

            getmlen(ch, cur)

            dp[idx] = ov

            



dp = []

dp.append(a[0])

mlen[0] = 1

getmlen(0, -1)



for i in range(n):

    print((mlen[i]))

#!/usr/bin/python3
import sys
from bisect import bisect_left

sys.setrecursionlimit(1000000)
n = int(eval(input()))
a = [int(i) for i in input().split()]
nbs = [[] for _ in range(n)]
for _ in range(n - 1):
    (u, v) = list(map(int, input().split()))
    nbs[u - 1].append(v - 1)
    nbs[v - 1].append(u - 1)
mlen = [0] * n
dp = [float("inf")] * n


def getmlen(cur, p, ctail):
    for ch in nbs[cur]:
        if ch == p:
            continue
        idx = bisect_left(dp, a[ch])
        ov = dp[idx]
        ntail = max(ctail, idx)
        dp[idx] = a[ch]
        mlen[ch] = ntail + 1
        getmlen(ch, cur, ntail)
        dp[idx] = ov


dp[0] = a[0]
mlen[0] = 1
getmlen(0, -1, 0)
for i in range(n):
    print((mlen[i]))

#!/usr/bin/python3
import sys
from bisect import bisect_left

sys.setrecursionlimit(1000000)
n = int(eval(input()))
a = [int(i) for i in input().split()]
nbs = [[] for _ in range(n)]
for _ in range(n - 1):
    (u, v) = list(map(int, input().split()))
    nbs[u - 1].append(v - 1)
    nbs[v - 1].append(u - 1)
mlen = [0] * n


def getmlen(cur, p):
    for ch in nbs[cur]:
        if ch == p:
            continue
        if a[ch] > dp[-1]:
            dp.append(a[ch])
            mlen[ch] = len(dp)
            getmlen(ch, cur)
            dp.pop(-1)
        else:
            idx = bisect_left(dp, a[ch])
            ov = dp[idx]
            dp[idx] = a[ch]
            mlen[ch] = len(dp)
            getmlen(ch, cur)
            dp[idx] = ov


dp = []
dp.append(a[0])
mlen[0] = 1
getmlen(0, -1)
for i in range(n):
    print((mlen[i]))

-dp = [float("inf")] * n -def getmlen(cur, p, ctail): +def getmlen(cur, p): -        idx = bisect_left(dp, a[ch]) -        ov = dp[idx] -        ntail = max(ctail, idx) -        dp[idx] = a[ch] -        mlen[ch] = ntail + 1 -        getmlen(ch, cur, ntail) -        dp[idx] = ov +        if a[ch] > dp[-1]: +            dp.append(a[ch]) +            mlen[ch] = len(dp) +            getmlen(ch, cur) +            dp.pop(-1) +        else: +            idx = bisect_left(dp, a[ch]) +            ov = dp[idx] +            dp[idx] = a[ch] +            mlen[ch] = len(dp) +            getmlen(ch, cur) +            dp[idx] = ov -dp[0] = a[0] +dp = [] +dp.append(a[0]) -getmlen(0, -1, 0) +getmlen(0, -1)