#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

int N, a[200005];
int dp[200005], ans[200005];
vector<int> adj[200005];

void rec(int v, int p) {
    int i = lower_bound(dp, dp+N, a[v]) - dp;
    int prev = dp[i];

    // 更新
    dp[i] = a[v];
    ans[v] = max(ans[p], i+1);

    // 子へ
    for (int u : adj[v]) if (u != p) rec(u, v);

    // 戻す
    dp[i] = prev;
}

int main() {
    cin >> N;
    for_(i,0,N) cin >> a[i];
    for_(i,0,N-1) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }    

    for_(i,0,N+1) dp[i] = 1L << 30;
    ans[N] = 0;
    rec(0, N);
    for_(i,0,N) cout << ans[i] << endl;
}