#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
int a[200001],dp[200001],ans[200001];
vector<int> Graph[200001];

void dfs(int now,int parent,int mx){
  int ng=0,ok=mx,mid;
  while(ok-ng>1){
    mid = ng + (ok - ng)/2;
    if(dp[mid]<a[now]) ng = mid;
    else ok = mid;
  }
  int save = dp[ok];
  dp[ok] = a[now];
  ans[now] = (ok==mx?mx++:mx-1);
  for(int child:Graph[now]) if(child != parent) dfs(child,now,mx);
  dp[ok] = save;
}

int main() {
  int n,u,v;
  cin >> n;
  for(int i=1;i<=n;i++) cin >> a[i];
  for(int i=1;i<=n-1;i++){
    cin >> u >> v;
    Graph[u].push_back(v);
    Graph[v].push_back(u);
  }
  for(int i=1;i<=n;i++) dp[i]=2e9;
  dfs(1,-1,1);
  for(int i=1;i<=n;i++) cout << ans[i] << endl;
}
