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

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vi; 
typedef vector<pll> vpll; 
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
#define endl        '\n'
#define pb          push_back
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define rs(v,n)     v.resize(n)
#define hell        1000000007
//#define hell        998244353
#define peak        9e18
#define pii         acos(-1)
#define clr(a,x)    memset(a,x,sizeof(a))
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

namespace Ops{
template<class y,class z> z expo(ll b,y e,z m){ll a=1;b%=m;while(e!=0){if((e&1)==1){a=a*b;a=a%m;}b=b*b;b%=m;e>>=1;}return a%m;}
template<class y,class z> z power(ll b,y e){ll a=1;while(e!=0){if((e&1)==1){a=a*b;}b=b*b;e>>=1;}return a;}
template<class x,class z> z inv(x b,z m){return expo(b,m-2,m);}
template<class x,class y> x invGeneral(x a,y b){if(a==0)return b==1?0:-1;x m=invGeneral(b%a,a);return m==-1?-1:((1-(ll)b*m)/a+b)%b;}
template<class x,class y> x min(x a,y b){x c;if(a<=b)c=a;else c=b;return c;}
template<class x,class y> x max(x a,y b){x c;if(a>=b)c=a;else c=b;return c;}
}
using namespace Ops;


namespace InOp{
template<class x>istream &operator>>(istream &in,vector<x> &v) {for(auto& i:v)in>>i;return in;}
template<class x,class y> ostream &operator<<(ostream &out,pair<x,y> &p) {out<<"("<<p.F<<","<<p.S<<")";return out;}
template<class x> ostream &operator<<(ostream &out,vector<x> &v) {out<<"Size : "<<v.size()<<endl;for(auto i:v)out<<i<<" ";out<<endl;return out;}
}
using namespace InOp;


namespace Debug{
#define LOCAL
#ifdef LOCAL
#define deb(...) printall(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void printall(const char* name, Arg1&& arg1){cerr<<name<<" : "<<arg1<<endl;}
template <typename Arg1, typename... Args>
void printall(const char* names,Arg1&& arg1,Args&&... args){const char* comma=strchr(names,',');cerr.write(names,comma-names)<<" : " <<arg1<<" | ";printall(comma+1,args...);}
#else
#define deb(...) void(0)
#endif
}
using namespace Debug;

namespace Bits{
template<class x> constexpr int onbits(x a){return __builtin_popcount(a);}
constexpr int bits(long long x){return 64-__builtin_clzll(x);}//take care of 0
constexpr int bits(int x){return 32-__builtin_clz(x);}//take care of 0
constexpr int traz(int a){return __builtin_ctz(a);}
constexpr int traz(long long a){return __builtin_ctzll(a);}
}
using namespace Bits;

namespace YesNo{
//#define CAPITAL
void yes(){
    #ifdef CAPITAL
    cout<<"YES"<<"\n";
    #else
    cout<<"Yes"<<"\n";
    #endif
}
void no(){
    #ifdef CAPITAL
    cout<<"NO"<<"\n";
    #else
    cout<<"No"<<"\n";
    #endif
}
}
using namespace YesNo;

void maester();
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout<<fixed<<setprecision(6);
    ll test=1;
    // cin>>test;
    while(test--)
    {
        maester();
    }
    #ifndef ONLINE_JUDGE
    cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
    #endif
    return 0;
}
#define N  500005
vi v[N],vis(N),val(N),anss(N,0);
ll ans=0,n;
void init(ll n)
{
    for(ll i=0;i<=n;i++)
    {
        v[i].clear();
        vis[i]=0;
        val[i]=0;
    }
}
vi a(N),seg(4*N);
void build(ll cur,ll st,ll end)
{
    if(st==end)
    {
        seg[cur]=a[st];
        return;
    }
    ll mid=(st+end)>>1;
    build(2*cur,st,mid);
    build(2*cur+1,mid+1,end);
    seg[cur]=max(seg[2*cur],seg[2*cur+1]);    /*  1-change here  */
}
ll query(ll cur,ll st,ll end,ll l,ll r)
{
    if(l<=st&&r>=end)
    return seg[cur];
    if(r<st||l>end)
    return 0;                           /*  2-change here  */
    ll mid=(st+end)>>1;
    ll ans1=query(2*cur,st,mid,l,r);
    ll ans2=query(2*cur+1,mid+1,end,l,r);
    return max(ans1,ans2);                 /*  3-change here  */
}
void update(ll cur,ll st,ll end,ll pos,ll upd)
{
    if(st==end)
    {
        a[pos]=upd;                    /*  4-change here  */
        seg[cur]=upd;                    /*  5-change here  */
        return;
    }
    ll mid=(st+end)>>1;
    if(st<=pos&&pos<=mid)
        update(2*cur,st,mid,pos,upd);
    else
        update(2*cur+1,mid+1,end,pos,upd);
    seg[cur]=max(seg[2*cur],seg[2*cur+1]);    /*  6-change here  */
}
void dfs(ll x,ll p)
{
    // ll prev=query(1,0,n,val[x],val[x]);
    // ll int cur=max(prev,1ll+query(1,0,n,0,val[x]-1));
    // update(1,0,n,val[x],cur);
    // anss[x]=query(1,0,n,0,cnt);
    // for(auto i:adj[node])
    // {
    //     if(!vis[i])
    //     {
    //         dfs(i);
    //     }
    // }
    // update(1,1,cnt,arr[node],prev);
    // deb(a);
    ll ansi=query(1,0,n,0,val[x]-1);
    ansi+=1;
    // deb(x,ansi);
    ans=max(ansi,ans);
    ll y=query(1,0,n,val[x],val[x]);
    ll yi=max(y,ansi);
    update(1,0,n,val[x],yi);
    ansi=query(1,0,n,0,n);
    anss[x]=ansi;
    for(auto i:v[x])
    {
        if(i==p)continue;
        dfs(i,x);
    }
    update(1,0,n,val[x],y);
}
void maester()
{
    ll i,j,k,l,r,m,x,y;
    cin>>n;
    ans=0;
    init(n);
    map<ll,ll> ma;
    for(i=1;i<=n;i++)
    {
        cin>>val[i];
        ma[val[i]]=1;
    }
    j=0;
    for(auto i:ma)
    {
        ma[i.F]=j;
        j++;
    }
    for(i=1;i<=n;i++)val[i]=ma[val[i]];
    for(i=0;i<n-1;i++)
    {
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    for(i=0;i<=n;i++)a[i]=0;
    build(1,0,n);
    dfs(1,1);
    // if(ans<=1)
    // {
    //     cout<<0<<endl;
    //     return;
    // }
    // cout<<ans<<endl;
    for(i=1;i<=n;i++)cout<<anss[i]<<endl;
}

Measured memory_bytes: 72052