// Original C++ solution (slower):
/*

[ ( ^ _ ^ ) ]

*/

// problem: atc/abc165_f

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define INF 1000000000



const int nax = 200005;

const int sz = 4 * nax;

vector<int> segtree(sz);

vector<vector<int>> g(nax);

vector<int> a(nax), rs(nax);

int n;





void upd(int idx, int s, int e, int p, int v) {

    if(p<s || e<p || e<s) return;

    if(s==p && e==p) {

        segtree[idx] = v;

        return;

    }

    int mid = s + (e-s)/2;

    int l = 2*idx; int r = l + 1;

    if(p<=mid) {

        upd(l, s, mid, p, v);

    } else {

        upd(r, mid+1, e, p, v);

    }

    segtree[idx] = max(segtree[l], segtree[r]);

}



int get(int idx, int s, int e, int l, int r) {

    if(e<s) return 0;

    if(r<s || e<l) return 0;

    if(l<=s && e<=r) {

        return segtree[idx];

    }

    int mid = s + (e-s)/2;

    int lc = 2*idx; int rc = lc+1;

    int x = get(lc, s, mid, l, r);

    int y = get(rc, mid+1, e, l, r);

    return max(x, y);

}



int get(int idx, int s, int e, int p) {

    return get(1, s, e, p, p);

}



void dfs(int v, int p) {

    int mx = get(1, 0, n-1, 0, a[v]-1);

    rs[v] = mx+1;

    int prev = get(1, 0, n-1, a[v]);

    upd(1, 0, n-1, a[v], max(rs[v], prev));

    for(int u: g[v]) {

        if(u==p) continue;

        dfs(u, v);

    }

    upd(1, 0, n-1, a[v], prev);

}



void dfs2(int v, int p) {

    for(int u: g[v]) {

        if(u==p) continue;

        rs[u] = max(rs[u], rs[v]);

        dfs2(u, v);

    }

}



int main() {

    scanf("%d", &n);

    vector<int> b(n+1);

    for(int i=1; i<=n; i++) {

        scanf("%d", &a[i]);

        b[i] = a[i];

    }

    sort(b.begin()+1, b.end());

    for(int i=1; i<=n; i++) {

        a[i] = lower_bound(b.begin()+1, b.end(), a[i]) - (b.begin()+1) + 1;

    }

    for(int i=0; i<n-1; i++) {

        int u, v;

        scanf("%d%d", &u, &v);

        g[u].emplace_back(v);

        g[v].emplace_back(u);

    }

    dfs(1, -1);

    dfs2(1, -1);

    for(int i=1; i<=n; i++) {

        printf("%d\n", rs[i]);

    }

}


// Optimized solution to the same problem (faster):
/*

[ ( ^ _ ^ ) ]

*/

// problem: atc/abc165_f

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define INF 1000000000





const int nax = 200005;

vector<vector<int>> g(nax);

vector<int> a(nax), rs(nax), dp(nax, INF);

int n;





void dfs(int v, int p) {

    int idx = lower_bound(dp.begin(), dp.end(), a[v]) - dp.begin();

    int prev = dp[idx];

    dp[idx] = a[v];

    rs[v] = idx+1;

    for(int u: g[v]) {

        if(u==p) continue;

        dfs(u, v);

    }

    dp[idx] = prev;

}



void dfs2(int v, int p) {

    for(int u: g[v]) {

        if(u==p) continue;

        rs[u] = max(rs[u], rs[v]);

        dfs2(u, v);

    }

}



int main() {

    scanf("%d", &n);

    for(int i=1; i<=n; i++) {

        scanf("%d", &a[i]);

    }

    for(int i=0; i<n-1; i++) {

        int u, v;

        scanf("%d%d", &u, &v);

        g[u].emplace_back(v);

        g[v].emplace_back(u);

    }

    dfs(1, -1);

    dfs2(1, -1);

    for(int i=1; i<=n; i++) {

        printf("%d\n", rs[i]);

    }

    // printf("\n");

}


// Fastest known solution for this problem: