#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;

Graph g;
vector<int> a, ans;
const int N = 2000005;
const int INF = 1000000000;
int dp[N];

void dfs(int v, int p=-1) {
  int i = lower_bound(dp, dp + N, a[v]) - dp;
  int old = dp[i];
  dp[i] = a[v];
  ans[v] = i;
  if (p != -1) ans[v] = max(ans[v], ans[p]);
  for(int u : g[v]) {
    if (u == p) continue;
    dfs(u, v);
  }
  dp[i] = old;
}

int main() {
  int n;
  cin >> n;
  g.resize(n);
  a.resize(n);
  ans.resize(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--;
    g[u].push_back(v);
    g[v].push_back(u);
  }

  dp[0] = -INF;
  for(int i = 1; i < N; ++i) {
    dp[i] = INF;
  }
  dfs(0);
  for(int i = 0; i < n; ++i) {
    cout << ans[i] << endl;
  }
  return 0;
}