#line 2 "header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

// template version 2.0
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define int long long
const int INF = 1e18;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (int i = (int)((b)-1); i >= (int)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T>
inline void chmax(T &a, const T &b) {
    if ((a) < (b)) (a) = (b);
}
template <class T>
inline void chmin(T &a, const T &b) {
    if ((a) > (b)) (a) = (b);
}

#define divceil(a, b) ((a) + (b)-1) / (b)
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x)    \
    sort(all(x)); \
    x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int, int> pii;
typedef tuple<int, int, int> iii;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
    }
} fast;
void check_input() {
    assert(cin.eof() == 0);
    int tmp;
    cin >> tmp;
    assert(cin.eof() == 1);
}

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"

// snippet:segment_tree {{{
template <typename T> struct SegmentTree {  // {{{
    private:
        using F = function<T(T, T)>;
        ll n;  // 元の配列のサイズ
        ll N;  // n以上の最小の2冪
        vector<T> node;
        F merge;
        T identity;

    public:
        SegmentTree() {}
        SegmentTree(vector<T> a, F f, T id) : merge(f), identity(id) {
            n = a.size();
            N = 1;
            while (N < n) N *= 2;
            node.resize(2 * N - 1, identity);
            for (ll i = 0; i < n; i++) node[i + N - 1] = a[i];
            for (ll i = N - 2; i >= 0; i--)
                node[i] = merge(node[2 * i + 1], node[2 * i + 2]);
        }
        SegmentTree(ll n, F f, T id) : SegmentTree(vector<T>(n, id), f, id) {}

        T& operator[](ll i) { return node[i + N - 1]; }

        void update(ll i, T val) {
            i += (N - 1);
            node[i] = val;
            while (i > 0) {
                i = (i - 1) / 2;
                node[i] = merge(node[2 * i + 1], node[2 * i + 2]);
            }
        }

        void add(ll i, T val) {
            i += (N - 1);
            node[i] += val;
            while (i > 0) {
                i = (i - 1) / 2;
                node[i] = merge(node[2 * i + 1], node[2 * i + 2]);
            }
        }

        // query for [l, r)
        T query(ll a, ll b, ll k = 0, ll l = 0, ll r = -1) {
            if (r < 0) r = N;
            if (r <= a || b <= l) return identity;
            if (a <= l && r <= b) return node[k];

            T vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
            T vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
            return merge(vl, vr);
        }

#if defined(PCM) || defined(LOCAL)
        friend ostream& operator<<(ostream& os, SegmentTree<T>& sg) {  //
            os << "[";
            for (ll i = 0; i < sg.n; i++) {
                os << sg[i] << (i == sg.n - 1 ? "]\n" : ", ");
            }
            return os;
        }
#endif
};/*}}}*/
// sample of initialize SegmentTree:
// -----------------------------------------------
// auto mymin=[](auto a, auto b){return min(a,b);};
// SegmentTree<ll> seg(a, mymin, 1e18);

// auto mymax=[](auto a, auto b){return max(a,b);};
// SegmentTree<ll> seg(a, mymax, -1e18);

// auto add=[](auto a, auto b){return a+b;};
// SegmentTree<ll> seg(a, add, 0);
// -----------------------------------------------
// snippet:segment_tree }}}

// snippet:tree {{{
template<class Cost=ll>
struct tree { 
    ll n;
    vector<ll> par;   // par[i]: dfs木における親
    vector<Cost> cost;  // par[i]: dfs木における親への辺のコスト
    vector<ll> dfstrv;  // dfstrv[i]: dfs木でi番目に訪れるノード。dpはこれを逆順に回す
    vector<ll> ord;    // ord[u]: uのdfs木における訪問順
    vector<ll> end;    // end[u]: uのdfs終了時のカウンター
    vector<ll> psize;  // psize[u]: uのpartial tree size
    // uの部分木は[ord[u], end[u])
    // ordとdfstrvは逆変換
    vector<ll> depth;   // depth[i]: dfs木でのiの深さ
    vector<Cost> ldepth;  //  ldepth[i]: dfs木でのrootからの距離
    vector<vector<pair<ll, Cost>>> g;  // 辺(隣接リスト)
    vector<vector<ll>> adj;           // 辺(隣接リスト)
    vector<vector<ll>> children;
    vector<ll> euler_tour;
    vector<ll> et_fpos;    // euler_tour first occurence position
    SegmentTree<ll> _seg;  // seg(map(ord, euler_tour), mymin, 1e18)
    vector<ll> head_of_comp;
    ll _counter = 0;

    tree(){};/*{{{*/
    tree(ll n)
        : n(n),
        par(n),
        cost(n),
        ord(n),
        end(n),
        psize(n),
        depth(n),
        ldepth(n),
        g(n),
        adj(n),
        children(n),
        et_fpos(n),
        head_of_comp(n){};/*}}}*/
    void add_edge(ll u, ll v, Cost cost) { /*{{{*/
        g[u].emplace_back(v, cost);
        g[v].emplace_back(u, cost);
        adj[u].emplace_back(v);
        adj[v].emplace_back(u);
    }                             /*}}}*/
    void add_edge(ll u, ll v) { /*{{{*/
        g[u].emplace_back(v, 1);
        g[v].emplace_back(u, 1);
        adj[u].emplace_back(v);
        adj[v].emplace_back(u);
    }                      /*}}}*/
    void build(ll root) { /*{{{*/
        _counter = 0;
        // par[root] = -1;
        // cost[root] = -1;
        _dfs_psize(root, -1);
        _dfs_tree(root, -1, root);
        _dfs_et(root);
        vector<ll> ini(2 * n - 1);
        rep(i, 2 * n - 1) ini[i] = ord[euler_tour[i]];
        _seg = SegmentTree<ll>(
                ini, [](auto a, auto b) { return min(a, b); }, 1e18);
    }                                /*}}}*/
    ll _dfs_psize(ll u, ll pre) { /*{{{*/
        psize[u] = 1;
        each(el, g[u]) {
            ll v = el.first;
            if (v == pre) continue;
            psize[u] += _dfs_psize(v, u);
        }
        return psize[u];
    }                                               /*}}}*/
    void _dfs_tree(ll u, ll pre, ll head_node) { /*{{{*/
        dfstrv.pb(u);
        ord[u] = _counter;
        if (pre != -1) {
            depth[u] = depth[pre] + 1;
            ldepth[u] = ldepth[pre] + cost[u];
        }

        _counter++;
        {
            // set most heavy child to top
            ll max_psize = 0;
            ll most_heavy_i = -1;
            rep(i, sz(g[u])) {
                if (g[u][i].first == pre) continue;
                if (psize[g[u][i].first] > max_psize) {
                    most_heavy_i = i;
                    max_psize = psize[g[u][i].first];
                }
            }
            if (most_heavy_i != -1) swap(g[u][most_heavy_i], g[u][0]);
        }

        head_of_comp[u] = head_node;
        rep(i, sz(g[u])) {
            ll v = g[u][i].first;
            if (v == pre) continue;

            children[u].pb(v);
            par[v] = u;
            cost[v] = g[u][i].second;

            if (i == 0)
                _dfs_tree(v, u, head_node);  // continue components
            else
                _dfs_tree(v, u, v);  // new
        }
        end[u] = _counter;
    }                     /*}}}*/
    void _dfs_et(ll u) { /*{{{*/
        et_fpos[u] = euler_tour.size();
        euler_tour.pb(u);
        each(v, children[u]) {
            _dfs_et(v);
            euler_tour.pb(u);
        }
    }                       /*}}}*/
    ll lca(ll u, ll v) { /*{{{*/
        if (u == v) return u;
        if (et_fpos[u] > et_fpos[v]) swap(u, v);
        return dfstrv[_seg.query(et_fpos[u], et_fpos[v])];
    }                        /*}}}*/
    ll dist(ll u, ll v) { /*{{{*/
        ll p = lca(u, v);
        return depth[u] + depth[v] - 2 * depth[p];
    }                          /*}}}*/
    Cost ldist(ll u, ll v) {  // length dist{{{
        ll p = lca(u, v);
        return ldepth[u] + ldepth[v] - 2 * ldepth[p];
    }                           /*}}}*/
    pair<ll, ll> diameter() { /*{{{*/
        ll u, v;
        Cost max_len = *max_element(all(ldepth));
        rep(i, n) {
            if (ldepth[i] == max_len) {
                u = i;
                break;
            }
        }
        Cost md = -1;
        rep(i, n) {
            Cost d = ldist(u, i);
            if (d > md) {
                v = i;
                md = d;
            }
        }
        return mp(u, v);
    }                                                /*}}}*/
    vector<pair<ll, ll>> hld_path(ll u, ll v) {  //{{{
        // 閉区間をvectorで返す
        vector<pair<ll, ll>> res;
        while (head_of_comp[u] != head_of_comp[v]) {
            if (depth[head_of_comp[u]] < depth[head_of_comp[v]]) {
                res.push_back({ord[head_of_comp[v]], ord[v]});
                v = par[head_of_comp[v]];
            } else {
                res.push_back({ord[head_of_comp[u]], ord[u]});
                u = par[head_of_comp[u]];
            }
        }
        res.push_back({min(ord[u], ord[v]), max(ord[u], ord[v])});
        return res;
    }                              //}}}
#if defined(PCM) || defined(LOCAL) /*{{{*/
    friend ostream& operator<<(ostream& os, const tree& tr) {
        os << endl;
        os << "par:         " << tr.par << endl;
        os << "cost:        " << tr.cost << endl;
        os << "dfstrv:      " << tr.dfstrv << endl;
        os << "ord:         " << tr.ord << endl;
        os << "end:         " << tr.end << endl;
        os << "depth:       " << tr.depth << endl;
        os << "children:    " << tr.children << endl;
        os << "euler_tour:  " << tr.euler_tour << endl;
        os << "et_fpos:     " << tr.et_fpos << endl;
        os << "head_of_comp:" << tr.head_of_comp << endl;
        return os;
    }
#endif /*}}}*/
}; 
// snippet:tree }}}

signed main() {
    //input
    ll n;cin>>n;
    tree tr(n);
    vector<ll> a(n);
    rep(i, n) {
        cin>>a[i];
    }
    dump(a);

    vvi gg(n);
    rep(i, n-1){
        ll u,v;cin>>u>>v;
        u--;v--;
        tr.add_edge(u, v);
        gg[u].pb(v);
        gg[v].pb(u);
    }
    // tr.build(0);
    // dump(tr);

    // check_input();
    //solve

    vi dp(n+3, INF);

    vector<pii> pre(n);
    vi ans(n);
    vector<ll> used(n);
    auto dfs = [&](const auto& dfs, ll u, ll prescore) -> void {
        dump(u, dp);
        used[u] = 1;
        ll j = lb(all(dp), a[u]) - dp.begin();
        ans[u] = prescore;
        chmax(ans[u], j + 1);
        ll old = dp[j];
        dp[j] = a[u];
        dump(u, dp);
        each(e, gg[u]){
            if (used[e]) continue;
            dfs(dfs, e, ans[u]);
        }
        dp[j] = old;
    };
    dfs(dfs, 0, -1);

    rep(i, n){
        cout << ans[i] << endl;
    }

    return 0; 
}



Measured memory_bytes: 85144