#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>;
vector<ll> a,ans;
vector<ll> p;
vector<int> ki[220000];
const ll INF = 100100100100100100LL;
void dfs(int now,int last = -1){
    int ind = lower_bound(p.begin(),p.end(),a[now])- p.begin();
    ll old = p[ind];
    
    p[ind] = a[now];
    ans[now] = lower_bound(p.begin(),p.end(),INF)-p.begin();
    
    for(auto next:ki[now]){
        if(next == last)continue;

        dfs(next,now);
    }
    p[ind] = old;
}
int main()
{
    int n;cin >> n;
    a.resize(n);
    ans.resize(n);
    p = vector<ll>(n,INF);
    
    rep(i,n)cin >> a[i];
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        a--;b--;
        ki[a].push_back(b);
        ki[b].push_back(a);
    }
    dfs(0);
    rep(i,n)cout << ans[i] << endl;
    return 0;
}