#include <bits/stdc++.h>
using namespace std;
int n;
int a[200005];
int ans[200005];
int L[200005];
vector<int> adjlist[200005];
void dfs(int u, int p, int l){
    //printf("%d %d %d\n",u,p,l);
    int pos = lower_bound(L,L+l,a[u])-L;
    int temp = L[pos];
    L[pos] = a[u];
    if (pos == l) l++;
    ans[u] = l;
    for (auto v:  adjlist[u]){
        if (v == p) continue;
        dfs(v,u,l);
    }
    L[pos] = temp;
}
int main(){
    scanf("%d",&n);
    for (int i = 1; i <= n; i++){
        scanf("%d",&a[i]);
    }
    for (int i = 1; i < n; i++){
        int u,v;
        scanf("%d%d",&u,&v);
        adjlist[u].push_back(v);
        adjlist[v].push_back(u);
    }
    dfs(1,-1,0);
    for (int i = 1; i <= n; i++){
        printf("%d\n",ans[i]);
    }
}
