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

typedef long long ll;

const int N = 200005;
int n;
int A[N];
vector<int> edges[N];
vector<int> V(N, INT_MAX);
int res[N];

void dfs(int par, int u) {
    for (auto v : edges[u]) {
        if (v == par) continue;
        int pos = lower_bound(V.begin(), V.end(), A[v]) - V.begin();

        res[v] = max(res[u], pos + 1);

        int temp = V[pos];
        V[pos] = A[v];
        dfs(u, v);
        V[pos] = temp;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> A[i];
    }
    int u, v;
    for (int i = 0; i < n - 1; ++i) {
        cin >> u >> v;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }
    res[1] = 1;
    V[0] = A[1];
    dfs(0, 1);

    for (int i = 1; i <= n; ++i) {
        cout << res[i] << endl;
    }

    return 0;
}

