#include <cstdio>
#include <vector>
#include <algorithm>
#define N 200005

int n;
int a[N], f[N], ans[N];
std::vector<int> v[N];

void dfs(int x, int fa) {
    int p = std::lower_bound(f, f + ans[fa], a[x]) - f;
    int t = f[p];
    f[p] = a[x];
    ans[x] = std::max(ans[fa], p + 1);
    for (int i : v[x])
        if (i != fa)
            dfs(i, x);
    f[p] = t;
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", a + i);
    for (int i = 1, x, y; i < n; ++i) {
        scanf("%d%d", &x, &y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    dfs(1, 0);
    for (int i = 1; i <= n; ++i) printf("%d\n", ans[i]);
    return 0;
}
