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

int n;
vector<int> dp(200010);
vector<int> ans(200010);
vector<int> a(200010);
vector<vector<int>> tr(200010);

void dfs(int v, int p=-1)
{
  int i = lower_bound(dp.begin(), dp.end(), a[v]) - dp.begin();
  int old = dp[i];
  dp[i] = a[v];
  ans[v] = lower_bound(dp.begin(), dp.end(), INF) - dp.begin();
  for (int u : tr[v]) {
    if (u == p) continue;
    dfs(u, v);
  }
  dp[i] = old;
}

int main()
{
  cin >> n;
  for (int i=0; i<n; i++){
    cin >> a[i];
  }
  for (int i=0; i<n-1; i++){
    int u, v; cin >> u >> v; u--; v--;
    tr[u].push_back(v);
    tr[v].push_back(u);
  }
  rep(i, 200010) dp[i] = INF;
  dfs(0);
  for (int i=0; i<n; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}
