#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

// chmax, chmin
template <class T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };

using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T &data, vector<int> &iter)
{
  cout << data << " ";
}
template <typename T>
void dump(const vector<T> &data, vector<int> &iter)
{
  for (auto elem : data)
    dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>> &data, vector<int> &iter)
{
  for (auto elem : iter)
  {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++)
  {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T> &data, int dummy)
{
  for (int i = 0; i < data.size(); i++)
  {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T &data)
{ // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////

void solve(long long N, std::vector<long long> A, std::vector<long long> U, std::vector<long long> V)
{
  vector<vector<int>> edges(N);
  for (int i = 0; i < N - 1; i++)
  {
    auto u = U[i];
    auto v = V[i];
    u--;
    v--;
    edges[u].push_back(v);
    edges[v].push_back(u);
  }

  stack<PII> sta;
  sta.push(PII(0, 0));
  vector<int> status = {};
  vector<PII> rev(N);
  vector<int> used(N);
  vector<int> ans(N);
  while (!sta.empty())
  {
    PII cur = sta.top();
    sta.pop();
    int kind = cur.second;
    int v = cur.first;
    if (kind == 1)
    {
      if (rev[v].first == -10)
        status.pop_back();
      else
      {
        status[rev[v].first] = rev[v].second;
      }
      continue;
    }
    used[v] = 1;

    // kind == 0
    int pos = lower_bound(status.begin(), status.end(), A[v]) - status.begin();

    if (pos == status.size())
    {
      status.push_back(A[v]);
      rev[v] = PII(-10, pos);
    }
    else
    {
      rev[v] = PII(pos, status[pos]);
      status[pos] = A[v];
    }
    sta.push(PII(v, 1));
    for (auto u : edges[v])
    {
      if (used[u])
        continue;
      sta.push(PII(u, 0));
    }
    ans[v] = status.size();
  }
  for (auto val : ans)
    cout << val << endl;
}

int main()
{
  cout << setprecision(10);
  long long N;
  scanf("%lld", &N);
  std::vector<long long> a(N);
  for (int i = 0; i < N; i++)
  {
    scanf("%lld", &a[i]);
  }
  std::vector<long long> u(N - 1);
  std::vector<long long> v(N - 1);
  for (int i = 0; i < N - 1; i++)
  {
    scanf("%lld", &u[i]);
    scanf("%lld", &v[i]);
  }
  solve(N, std::move(a), std::move(u), std::move(v));
  return 0;
}


Measured memory_bytes: 26896