#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

constexpr int MAX = 200200;

vector<ll> zip(const vector<ll> &a) {
    vector<ll> b(a);
    sort(b.begin(), b.end());
    b.erase(unique(b.begin(), b.end()), b.end());
    vector<ll> ret(a.size());
    rep(i,a.size()) {
        ret[i] = lower_bound(b.begin(), b.end(), a[i])-b.begin();
    }
    return ret;
}

template <class T>
class SegTree {
    private:
        int n; // number of leaves
        vector<T> data; // vector which has datas
        T def; // init number & 単位元
        function<T(T,T)> operation; // 区間クエリで使う処理
        function<T(T,T)> update; // 点更新で使う処理

        T _query(int a, int b, int k, int l, int r) {
            // [a, b)のクエリ
            // ノードk(区間[l, r)担当)が答える
            if (b <= l || r <= a) return def; // 区間がかぶらなければdef
            if (a <= l && r <= b) return data[k]; // 区間が完全にかぶっていればdata[k]
            else {
                // 一部だけかぶる場合は左右の子に委託する
                ll c1 = _query(a, b, 2*k+1, l, (l+r)/2);
                ll c2 = _query(a, b, 2*k+2, (l+r)/2, r);
                return operation(c1, c2);
            }
        }

    public:

        SegTree(size_t _n, T _def, function<T(T,T)> _operation, function<T(T,T)> _update) :
            def(_def), operation(_operation), update(_update){
                n = 1;
                while (n < _n) {n *= 2;}
                data = vector<T>(2*n-1, def);
        }

        T query(T a, T b) {return _query(a,b,0,0,n);}

        void change(T i, T x) {
            i += n-1;
            data[i] = update(data[i],x);
            while (i>0) {
                i = (i-1)/2;
                data[i] = operation(data[i*2+1], data[i*2+2]);
            }
        }

        T operator[](int i) {return data[i+n-1];}
};

int cnt = 0;
int kaeri = 0;
void dfs(const vector<vector<int>> &g, SegTree<ll> &sg, vector<ll> &b, vector<ll> &ans, int c, int p) {
    // cout << "c = " << ++cnt << '\n';
    ll memo = sg.query(b[c], b[c]+1);
    ll t = sg.query(0, b[c]);
    sg.change(b[c], t+1);
    ans[c] = sg.query(0, MAX);
    for(auto &&e : g[c]) {
        if(p == e) continue;
        dfs(g, sg, b, ans, e, c);
    }
    sg.change(b[c], memo);
    // cout << "kaeri = " << ++kaeri << '\n';
    return;
}

int main() {
    int n; cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    
    vector<vector<int>> g(n);

    rep(i,n-1) {
        int u,v; cin>>u>>v; --u,--v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    vector<ll> b = zip(a);

    SegTree<ll> sg(MAX, 0ll, [](ll x, ll y){return max(x,y);},[](ll a, ll x){return x;});
    vector<ll> ans(n);
    /*
    auto dfs = [&](auto &&f, int c, int p) -> void {
        ll t = sg.query(0, b[c]);
        sg.change(b[c],t+1);
        ans[c] = sg.query(0,MAX);
        for (auto &&e: g[c]) {
            if (p==e) continue;
            f(f,e,c);
        }
        sg.change(b[c], 0);
        cout << "c = " << c << '\n';
        return;
    };
    */
    dfs(g, sg, b, ans, 0, -1);
    rep(i,n) cout << ans[i] << '\n';
    return 0;
}

Measured memory_bytes: 195640