/***************************************** START OF TEMPLATE *********************************************/
#include<bits/stdc++.h>

using namespace std;

#define  SPEED          ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  foo(i,a,n)     for(ll i = (a); i <= n; i++)
#define  frr(i,a,n)     for(ll i = (a); i >= n; i--)
#define  fo(i,n)        for(ll i = 0; i < n; i++)
#define  all(x)         (x).begin(),(x).end()
#define  mset(x,val)    memset(x,val,sizeof(x))
#define  newl           cout<<"\n"
#define  f              first
#define  s              second
#define  pb             push_back
#define  INPa(a,n)      foo(i,1,n) cin>>a[i];
#define  deb2d(a,n,m)   foo(i,1,n){foo(j,1,m){cout<<a[i][j]<<" ";}newl;}
#define  deb1d(a,n)     foo(i,1,n)cout<<a[i]<<" ";newl;
#define  debv(a)        for(auto it: a)cout<<it<<" ";newl;
#define  deb1(a)        cout<<a<<" ";newl;
#define  deb2(a,b)      cout<<a<<" "<<b<<" ";newl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<" ";newl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d;newl;
#define  ll             long long
#define  ld             long double
#define  pll            pair<ll,ll>
#define  vll            vector<ll>
#define  vpll           vector<pll>

const ll   MOD   =  1e+9 + 7;
const ll   INF   =  LLONG_MAX;
const int  INFi  =  INT_MAX;
const ll   N     =  2e+5 + 8;

vll adj[N]; ll vis[N];
ll dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};

ll test_cases = 1; randomINIT;

/*********************************************************************************************************/
/***************************************** VARIABLE DECLARATIONS *****************************************/
ll n, u, v, a[N], dp[N];
map<ll, ll> ID;
/***************************************** FUNCTION IMPLEMENTATIONS **************************************/
ll seg[4 * N + 8];

ll left(ll nd) {return nd << 1;}
ll right(ll nd) {return (nd << 1) + 1;}
ll combine(ll a, ll b) {return max(a, b);}

void update(ll node, ll st, ll en, ll pos, ll val) {
    if (st == en) {
        seg[node] = val;
        return;
    }
    ll mid = (st + en) / 2;
    if (pos <= mid) update(left(node), st, mid, pos, val);
    else update(right(node), mid + 1, en, pos, val);
    seg[node] = combine(seg[left(node)], seg[right(node)]);
}

ll query(ll node, ll st, ll en, ll l, ll r) {
    if (l <= st && en <= r) return seg[node];
    if (st > r || en < l) return 0;

    ll mid = (st + en) / 2;
    ll lq = query(left(node), st, mid, l, r);
    ll rq = query(right(node), mid + 1, en, l, r);

    return combine(lq, rq);
}


void dfs(ll v, ll p) {
    vis[v] = 1;
    ll cur = query(1, 1, N, ID[a[v]], ID[a[v]]);
    ll ans = query(1, 1, N, 1, ID[a[v]] - 1);
    dp[v] = max(dp[p], ans + 1);
    update(1, 1, N, ID[a[v]], ans + 1);

    for (auto to : adj[v]) {
        if (vis[to] == 0) {
            dfs(to, v);
        }
    }

    update(1, 1, N, ID[a[v]], cur);
    vis[v] = 0;
}

void path_compress() {
    set<ll> order;
    ll cnt = 1;
    foo(i, 1, n) order.insert(a[i]);
    for (auto it : order) ID[it] = cnt++;
}
/***************************************** START OF MAIN FUNCTION ****************************************/
void MAIN(ll tc) {
    cin >> n;
    INPa(a, n);
    foo(i, 1, n - 1) {
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    path_compress();
    dfs(1, 1);
    foo(i, 1, n)cout << dp[i] << "\n";
}

int main() {
    SPEED;

    //cin>>test_cases;
    foo(i, 1, test_cases) {
        MAIN(i);
    }
}

Measured memory_bytes: 60532