#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 fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define pii pair<int,int>
#define pf push_front
#define mp make_pair
#define vi vector<int>
#define vip vector<pair<int,int> >
#define ff first
#define ss second
#define int long long
#define mod 1000000007
#define BIG 998244353
#define s(t) scanf("%lld",&t)
#define p(t) printf("%lld\n",t)
#define mii map<int,int>
#define MSET(table,i) memset(table, i, sizeof(table))
#define endl '\n'
#define tc int t;cin>>t;while(t--)
#define pi  3.1415926358
#define bits(x) __builtin_popcount(x)
#define minimum(a,n) min_element(a,a+n)-a
#define maximum(a,n) max_element(a,a+n)-a
#define pqbig priority_queue<int>
#define pqsmall priority_queue<pii,vector<pii>,greater<pii> >
#define all(v) v.begin(),v.end()
#define sitr set<int>:: iterator
#define spitr set<pii>:: iterator
#define mitr map<int,int>:: iterator

int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ) {stringstream ss; ss << number; return ss.str();}


typedef tree<int, null_type, less<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;


#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

const int N=2e5+5;
vi adj[N];
multiset<int> s[N];
int st[4*N];
int arr[N];
int ans[N];
int n;

void update(int l,int r,int id,int val,int node)
{
    //trace1(node);
    if(l==r)
    {
        st[node]=val;
        return ;
    }

    int mid=(l+r)/2;
    //trace4(mid,l,r,id);
    if(id<=mid)
        update(l,mid,id,val,2*node);
    else
        update(mid+1,r,id,val,2*node+1);

    st[node]=max(st[2*node],st[2*node+1]);
}

int query(int l,int r,int ql,int qr,int node)
{
    if(ql>r or qr<l)
        return 0;
    if(ql<=l and qr>=r)
        return st[node];

    int mid=(l+r)/2;
    return max(query(l,mid,ql,qr,2*node),query(mid+1,r,ql,qr,2*node+1));
}

void dfs(int node,int pt,int pt_max)
{
    int val=arr[node];
    int num=query(1,n,1,val-1,1);
    ans[node]=max(pt_max,num+1);
    s[val].insert(num+1);

    //trace3(val,*s[val].rbegin(),node);

    update(1,n,val,*s[val].rbegin(),1);

    //trace2(node,val);

    for(int i=0;i<adj[node].size();i++)
    {
        int el=adj[node][i];
        if(el==pt)
            continue;
        dfs(el,node,ans[node]);
    }

    s[val].erase(s[val].find(num+1));
    if(s[val].size()==0)
        update(1,n,val,0,1);
    else
        update(1,n,val,*s[val].rbegin(),1);
}

int32_t main()
{
    fast;
    cin>>n;

    vi v(n);

    for(int i=1;i<=n;i++)
        cin>>arr[i],v[i-1]=arr[i];

    sort(all(v));
    for(int i=1;i<=n;i++)
        arr[i]=lower_bound(all(v),arr[i])-v.begin()+1;

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


    dfs(1,0,0);
    for(int i=1;i<=n;i++)
        cout<<ans[i]<<endl;
}

Measured memory_bytes: 58076