#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vi2;
typedef vector<vi2> vi3;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<ll> vll;
typedef vector<vll> vll2;
typedef vector<vll2> vll3;
typedef vector<bool> vb;

#define el '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repi(i, a, b) for (int i = a; i >= b; i--)
#define umap unordered_map
#define uset unordered_set
#define vec vector
#define loop(a) for (auto &x : a)
#define all(a) a.begin(), a.end()
#define mp make_pair

vi depth, order;
vii range;
vi2 adj;
int order_cnt;

vi t, lazy;

void dfs(int parent, int root) {
    order[root] = order_cnt++;
    loop(adj[root]) {
        if (x == parent) {
            continue;
        }
        depth[x] = depth[root] + 1;
        dfs(root, x);
    }
    range[root] = {order[root], order_cnt};
}

void push(int root) {
    if (lazy[root] > 0) {
        int left = root * 2 + 1;
        int right = left + 1;
        t[left] = max(t[left], lazy[root]);
        t[right] = max(t[right], lazy[root]);
        lazy[left] = max(lazy[left], lazy[root]);
        lazy[right] = max(lazy[right], lazy[root]);
        lazy[root] = 0;
    }
}

int query(int root, int low, int high, int idx) {
    if (idx < low || high <= idx) {
        return 0;
    }
    if (low + 1 == high) {
        return t[root];
    }
    push(root);
    int mid = (low + high) / 2;
    if (idx < mid) {
        return query(root * 2 + 1, low, mid, idx);
    } else {
        return query(root * 2 + 2, mid, high, idx);
    }
#ifdef LOCAL
    assert(t[root] == max(t[root * 2 + 1], t[root * 2 + 2]));
#endif
}

void update(int root, int low, int high, int qlow, int qhigh, int val) {
    if (qhigh <= low || high <= qlow) {
        return;
    }
    if (qlow <= low && high <= qhigh) {
        t[root] = max(t[root], val);
        lazy[root] = max(lazy[root], val);
        return;
    }
    push(root);
    int mid = (low + high) / 2;
    int left, right;
    update(left = root * 2 + 1, low, mid, qlow, qhigh, val);
    update(right = root * 2 + 2, mid, high, qlow, qhigh, val);
    t[root] = max(t[left], t[right]);
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    vii a(n);
    rep(i, 0, n) {
        cin >> a[i].first;
        a[i].second = i;
    }
    adj = vi2(n);
    rep(i, 0, n - 1) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    order = vi(n);
    depth = vi(n);
    range = vii(n);
    depth[0] = 0;
    dfs(0, 0);

    sort(all(a), [&](pii x, pii y) {
        return make_tuple(x.first, -depth[x.second], x.second) <
               make_tuple(y.first, -depth[y.second], y.second);
    });
    vi ans(n, 0);
    t = vi(4 * n);
    lazy = vi(4 * n);
    loop(a) {
        int i = x.second;
        ans[i] = query(0, 0, n, order[i]) + 1;
        update(0, 0, n, range[i].first, range[i].second, ans[i]);
    }
    // t.assign(4 * n, 0);
    // lazy.assign(4 * n, 0);
    // rep(i, 0, n) {
    //     update(0, 0, n, range[i].first, range[i].second, ans[i]);
    // }
    rep(i, 0, n) {
        cout << query(0, 0, n, order[i]) << el;
    }
}


Measured memory_bytes: 37076