local mfl = math.floor

local function comp(a, b)
  return a < b
end

local function lower_bound(ary, x)
  local num = #ary
  if num == 0 then return 1 end
  if not comp(ary[1], x) then return 1 end
  if comp(ary[num], x) then return num + 1 end
  local min, max = 1, num
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if comp(ary[mid], x) then
      min = mid
    else
      max = mid
    end
  end
  return max
end

local function upper_bound(ary, x)
  local num = #ary
  if num == 0 then return 1 end
  if comp(x, ary[1]) then return 1 end
  if not comp(x, ary[num]) then return num + 1 end
  local min, max = 1, num
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if not comp(x, ary[mid]) then
      min = mid
    else
      max = mid
    end
  end
  return max
end

local n = io.read("*n")
local t = {}
for i = 1, n do
  t[i] = io.read("*n")
end

local edge = {}
local asked = {}
local cpos = {}
local len = {}
local stpos = {}
for i = 1, n do
  edge[i] = {}
  asked[i] = false
  cpos[i] = 0
  len[i] = 0
  stpos[i] = 0
end
len[n + 1] = 1000000007
for i = 1, n - 1 do
  local x, y = io.read("*n", "*n")
  table.insert(edge[x], y)
  table.insert(edge[y], x)
end

local lis = {}
for i = 1, n + 1 do
  lis[i] = 1000000007
end
local ret = {}
for i = 1, n do ret[i] = 1 end
local tasks = {1}
local undotask = {}
local sti = 1
while 0 < #tasks do
  local src = tasks[#tasks]
  table.remove(tasks)
  if src == -1 then
    ubpos, v = undotask[#undotask][1], undotask[#undotask][2]
    table.remove(undotask)
    lis[ubpos] = v
  else
    if not asked[src] then
      asked[src] = true
      local ubpos = upper_bound(lis, t[src])
      table.insert(undotask, {ubpos, lis[ubpos]})
      lis[ubpos] = t[src]
      local r = lower_bound(lis, 1000000007) - 1
      ret[src] = r
    end
    -- print(src, len[src])
    stpos[src] = sti
    sti = sti + 1
    while cpos[src] < #edge[src] do
      cpos[src] = cpos[src] + 1
      local dst = edge[src][cpos[src]]
      if not asked[dst] then
        len[dst] = len[src] + 1
        table.insert(tasks, src)
        table.insert(tasks, -1)
        table.insert(tasks, dst)
        break
      end
    end
  end
end
print(table.concat(ret, "\n"))
