#include <bits/stdc++.h>
using namespace std;
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] = lower_bound(dp, dp + MAX_N, INF) - dp - 1;
    for (auto u : to[v])
    {
        if(u == p) continue;
        dfs(u, v);
    }
    dp[i] = old;
}

int main() {
    int N; cin >> N;
    a = ans = vector<int>(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    vector<vector<int>> G(N);
    for (int i = 0; i < N-1; i++)
    {
        int u, v; cin >> u >> v;
        u--; v--;
        to[u].push_back(v);
        to[v].push_back(u);
    }

    for(int i = 0; i < MAX_N; i++) dp[i] = INF;
    dp[0] = -INF;
    dfs(0);
    for (int i = 0; i < N; i++)
    {
        cout << ans[i] << endl;
    }

    return 0;
}