#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int n;
vector<int> a;
vector<vector<int>> e;
vector<int> dp;
vector<int> ans;

void dfs(int pre, int crt)
{
  auto ud = lower_bound(dp.begin(), dp.end(), a[crt]);
  int tmp = *ud;
  *ud = a[crt];
  if (crt != 0)
    if (tmp == INT_MAX)
      ans[crt] = ans[pre] + 1;
    else
      ans[crt] = ans[pre];
  for (int i : e[crt])
    if (i != pre)
      dfs(crt, i);
  *ud = tmp;
}

int main()
{
  cin >> n;
  a.resize(n);
  rep(i, n)
    cin >> a[i];
  e.resize(n);
  rep(i, n - 1)
  {
    int u, v;
    cin >> u >> v;
    e[u-1].push_back(v - 1);
    e[v-1].push_back(u - 1);
  }
  ans.resize(n);
  dp.resize(n);
  fill(dp.begin(), dp.end(), INT_MAX);
  ans[0] = 1;
  dfs(-1, 0);
  rep(i, n)
    printf("%d\n", ans[i]);
  return 0;
}