/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
// #define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define ar array
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MAXN = 202000;

// #define inf 1e11
int n, m, a[1<<18], t[1<<20] ;

struct Vertex {
    Vertex *l, *r;
    int mx;

    Vertex(int mx) : l(nullptr), r(nullptr), mx(mx) {}
    Vertex(Vertex *l, Vertex *r) : l(l), r(r), mx(0) {
        if (l) mx = max(mx, l->mx);
        if (r) mx = max(mx, r->mx);
    }
};
Vertex *T[(1<<20)];

Vertex* build(int a[], int tl, int tr) {
    if (tl == tr)
        return new Vertex(a[tl]);
    int tm = (tl + tr) / 2;
    return new Vertex(build(a, tl, tm), build(a, tm+1, tr));
}

int get_sum(Vertex* v, int tl, int tr, int l, int r) {
    if (l > r)
        return 0;
    if (l == tl && tr == r)
        return v->mx;
    int tm = (tl + tr) / 2;
    return max(get_sum(v->l, tl, tm, l, min(r, tm))
         , get_sum(v->r, tm+1, tr, max(l, tm+1), r));
}

Vertex* update(Vertex* v, int tl, int tr, int pos, int new_val) {
    if (tl == tr)
        return new Vertex(new_val);
    int tm = (tl + tr) / 2;
    if (pos <= tm)
        return new Vertex(update(v->l, tl, tm, pos, new_val), v->r);
    else
        return new Vertex(v->l, update(v->r, tm+1, tr, pos, new_val));
}

vi adj[MAXN];
int val[MAXN],intime[MAXN],ans[MAXN];
map<int,int> mp;
int tin = 1;

void dfs(int s, int p){

  intime[s] = tin++;
  ans[s] = max(ans[s],ans[p]);
  int cur = get_sum(T[intime[p]],0,n,0,mp[val[s]]-1);
  ans[s] = max(ans[s],cur+1);
  T[intime[s]] = update(T[intime[p]],0,n,mp[val[s]],cur+1);
  for(auto t:adj[s]){
    if(t!=p){
      dfs(t,s);
    }
  }

}

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  cin >> n;
  set<int> s;
  for(int i=1;i<=n;i++){
    cin >> val[i];
    s.insert(val[i]);
  }
  T[0] = build(a,0,n);
  // sort(all(v));
  mp[0]=0;
  int idx = 1;
  for(auto t:s){
    mp[t] = idx++;
  }

  for(int i=1;i<n;i++){
    int x,y;
    cin >> x >> y;
    adj[x].pb(y);
    adj[y].pb(x);
  }
  dfs(1,0);
  for(int i=1;i<=n;i++){
    cout << ans[i] << endl;
  }


return 0;
}
///....


Measured memory_bytes: 183564