#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
vector<vector<int> > adj;
vector<int> A, ans, s;

void dfs(int i, int p) {
    int j = lower_bound(s.begin(), s.end(), A[i]) - s.begin();
    int save = s[j];
    s[j] = A[i];
    ans[i] = max(ans[i], j);
    for (int j : adj[i]) {
        if (j != p) { ans[j] = ans[i]; dfs(j, i); }
    }
    s[j] = save;
}

int main() {
    int n; scanf("%d", &n);
    adj.resize(n);
    A.resize(n);
    for (int &a : A) scanf(" %d", &a);
    for (int i = 1; i < n; i++) {
        int u, v; scanf(" %d %d", &u, &v);
        u--; v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    ans.resize(n);
    s.resize(n, 1<<30);
    s[0] = 0;
    dfs(0, -1);
    for (int a : ans) printf("%d\n", a);
}
