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

const int MAX_N = 200005;
const int INF = 1001001001;

vector<int> A, ans;
vector<int> to[200005];
int dp[MAX_N];

void dfs(int v, int p = -1) {
  int i = lower_bound(dp, dp + MAX_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 : to[v]) {
    if (u == p) continue;
    dfs(u, v);
  }
  dp[i] = old;
}

int main() {
  int N;
  cin >> N;
  A = ans = vector<int>(N);
  rep(i, N) cin >> A[i];
  rep(i, N - 1) {
    int u, v;
    cin >> u >> v;
    u--; v--;
    to[u].push_back(v);
    to[v].push_back(u);
  }
  rep(i, MAX_N) dp[i] = INF;
  dp[0] = -INF;
  dfs(0);

  rep(i, N) cout << ans[i] << endl;
  return 0;
}
