#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL n,a[200010],x,y,n2=1,dat[800010],ans[200010];
vector <LL> g[200010],v;

void upd(LL k,LL val)
{
	dat[k]=val;
	while(k>0)
	{
		k=(k-1)/2;
		dat[k]=max(dat[k*2+1],dat[k*2+2]);
	}
}

LL query(LL k,LL lb,LL ub,LL tlb,LL tub)
{
	if(ub<tlb||tub<lb) return 0;
	if(tlb<=lb&&ub<=tub) return dat[k];
	return max(query(k*2+1,lb,(lb+ub)/2,tlb,tub),query(k*2+2,(lb+ub)/2+1,ub,tlb,tub));
}

void dfs(LL pos,LL par,LL mx)
{
	//cout<<pos<<' '<<a[pos]<<'p'<<endl;
	LL val=query(0,0,n2-1,0,a[pos]-1)+1;
	//cout<<val<<'k'<<endl;
	ans[pos]=max(mx,val);
	upd(a[pos]+n2-1,val);
	rep(i,g[pos].size()) if(g[pos][i]!=par) dfs(g[pos][i],pos,ans[pos]);
	upd(a[pos]+n2-1,0);
}

int main()
{
	cin>>n;
	repn(i,n)
	{
		scanf("%lld",&a[i]);
		v.pb(a[i]);
	}
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	while(n2<v.size()) n2*=2;
	repn(i,n) a[i]=lower_bound(v.begin(),v.end(),a[i])-v.begin();
	rep(i,n-1)
	{
		scanf("%lld%lld",&x,&y);
		g[x].pb(y);
		g[y].pb(x);
	}
	dfs(1,0,0);
	repn(i,n) cout<<ans[i]<<endl;
	return 0;
}