#include<bits/stdc++.h>

using namespace std;

#define fRead(x)        freopen(x,"r",stdin)
#define fWrite(x)       freopen (x,"w",stdout)

#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define PI              acos(-1.0)
#define mk              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr);
#ifdef VAMP
     #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template < typename Arg1 >
    void __f(const char* name, Arg1&& arg1){
        cout << name << " = " << arg1 << std::endl;
    }
    template < typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names+1, ',');
        cout.write(names, comma - names) << " = " << arg1 <<" | ";
        __f(comma+1, args...);
    }
#else
    #define debug(...)
#endif

const int N = 200005;
int n, ara[N];
vector<int>g[N];


struct data {
    int l, r, c;
    data() {
        l = r = c = 0;
    }
    data(int a, int b, int d) {
        l = a;
        r = b;
        c = d;
    }
}T[N * 20];

int Root[N], id;

int update(int pr, int b, int e, int pos,int val) {
    int node = ++id;
    T[node] = T[pr];
    if(b == e) {
        T[node].c = val;
        return node;
    }
    int mid = b + e >> 1;
    if(pos <= mid) T[node].l = update(T[node].l, b, mid, pos,val);
    else T[node].r = update(T[node].r, mid + 1, e, pos,val);
    T[node].c = max(T[ T[node].l ].c , T[ T[node].r ].c);
    return node;
}
int query(int pr, int L,int R,int l,int r) {
    if(R < l or r < L)return 0;
    if(L >= l and R <= r)return T[pr].c;
    int mid = L + R >> 1;
    int x = query(T[pr].l,L,mid,l,r);
    int y = query(T[pr].r,mid + 1,R,l,r);
    return max(x,y);
}
int ans[N];
void dfs(int node,int pre)
{
    int v = query(Root[pre],1,n,1,ara[node] - 1);

    Root[node] = update(Root[pre],1,n,ara[node],v + 1);
    ans[node] = T[Root[node]].c;

    for(int i : g[node]){
    
        if(i == pre)continue;
        dfs(i,node);
    }
}
int main()
{

    #ifdef VAMP
        clock_t tStart = clock();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    cin >> n;
    map<int,int>mp,to;
    FOR(i,1,n)cin >> ara[i] , mp[ara[i]] = 1;
    int ID = 0;
    for(auto x : mp)to[x.ff] = ++ID;
    FOR(i,1,n)ara[i] = to[ara[i]];


    for(int i = 1;i < n;i++){
        int a ,b;
        cin >> a >> b;
        g[a].pb(b);
        g[b].pb(a);
    }
    dfs(1,0);
    FOR(i,1,n)cout << ans[i] << "\n";
    #ifdef VAMP
        fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
    #endif
}


Measured memory_bytes: 93876