#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
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[MAX_N];
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;
}
