#include <bits/stdc++.h>
#define INF 0x7f7f7f7f
using namespace std;
const int N = 2e5 + 5;
vector<int> G[N] = {};
int val[N] = {};
int n;
stack<int> ls[N];
int ans[N] = {};
bool ha[N] = {};
int t = 0;
int bs(int x) {
    int l = 1, r = t, mid;
    while (l <= r) {
        mid = (l + r) >> 1;
        if (ls[mid].top() < x)
            l = mid + 1;
        else r = mid - 1;
    }
    return l;
}
void dfs(int u, int f) {
    int idx = bs(val[u]);
    if (val[u] < ls[idx].top()) {
        ha[u] = true;
        ls[idx].emplace(val[u]);
        t = max(idx, t);
    }
    ans[u] = t;
    for (const int &v : G[u])
        if (v != f) dfs(v, u);
    if (ha[u]) {
        ls[idx].pop();
        if (ls[idx].top() == INF)
            t--;
    }
}
int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> val[i];
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }
    ls[0].emplace(0);
    for (int i = 1; i <= n; i++)
        ls[i].emplace(INF);
    dfs(1, 0);
    for (int i = 1; i <= n; i++)
        cout << ans[i] << "\n";
    return 0;
}