#include <bits/stdc++.h>
using namespace std;
#define fi			first
#define se			second
#define fz(i,a,b)	for(int i=a;i<=b;i++)
#define fd(i,a,b)	for(int i=a;i>=b;i--)
#define foreach(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define all(a)		a.begin(),a.end()
#define giveup(...) return printf(__VA_ARGS__),0;
#define fill0(a)	memset(a,0,sizeof(a))
#define fill1(a)	memset(a,-1,sizeof(a))
#define fillbig(a)	memset(a,0x3f,sizeof(a))
#define fillsmall(a) memset(a,0xcf,sizeof(a))
#define mask(a)		(1ll<<(a))
#define maskx(a,x)	((a)<<(x))
#define _bit(a,x)	(((a)>>(x))&1)
#define _sz(a)		((int)(a).size())
#define filei(a)	freopen(a,"r",stdin);
#define fileo(a)	freopen(a,"w",stdout);
#define fileio(a) 	freopen(a".in","r",stdin);freopen(a".out","w",stdout)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define put(x)		putchar(x)
#define eoln        put('\n')
#define space		put(' ')
#define y1			y_chenxiaoyan_1
#define y0			y_chenxiaoyan_0
typedef pair<int,int> pii;
inline int read(){
	int x=0,neg=1;char c=getchar();
	while(!isdigit(c)){
		if(c=='-')	neg=-1;
		c=getchar();
	}
	while(isdigit(c))	x=x*10+c-'0',c=getchar();
	return x*neg;
}
inline void print(int x){
	if(x<0){
		putchar('-');
		print(abs(x));
		return;
	}
	if(x<=9)	putchar(x+'0');
	else{
		print(x/10);
		putchar(x%10+'0');
	}
}
inline int qpow(int x,int e,int _MOD){
	int ans=1;
	while(e){
		if(e&1)	ans=ans*x%_MOD;
		x=x*x%_MOD;
		e>>=1;
	}
	return ans;
}
int n=read(),a[200005],key[200005],hs[200005],cnt=0,dp[200005],dp2[200005];
vector<int> g[200005];
struct SegTree{
	struct node{
		int l,r,mx;
	} s[200005<<2];
	inline void build(int k,int l,int r){
		s[k].l=l;s[k].r=r;
		if(l==r)	return;
		int mid=(l+r)>>1;
		build(k<<1,l,mid);
		build(k<<1|1,mid+1,r);
	}
	inline void modify(int k,int ind,int x){
		if(s[k].l==s[k].r){
			s[k].mx=x;
			return;
		}
		int mid=(s[k].l+s[k].r)>>1;
		if(ind<=mid)	modify(k<<1,ind,x);
		else			modify(k<<1|1,ind,x);
		s[k].mx=max(s[k<<1].mx,s[k<<1|1].mx);
	}
	inline int query(int k,int l,int r){
		if(l>r)	return 0;
		if(l<=s[k].l&&s[k].r<=r){
			return s[k].mx;
		}
		int mid=(s[k].l+s[k].r)>>1;
		if(r<=mid)	return query(k<<1,l,r);
		else if(l>mid)	return query(k<<1|1,mid+1,r);
		else			return max(query(k<<1,l,mid),query(k<<1|1,mid+1,r));
	}
} st;
multiset<int> sts[200005];
inline void dfs(int x,int f){
	dp[x]=st.query(1,1,a[x]-1)+1;
	st.modify(1,a[x],dp[x]);
	sts[a[x]].insert(dp[x]);
//	cout<<x<<" "<<dp[x]<<endl;
	foreach(it,g[x]){
		int y=*it;
		if(y==f)	continue;
		dfs(y,x);
	}
	sts[a[x]].erase(sts[a[x]].find(dp[x]));
	if(!sts[a[x]].empty())	st.modify(1,a[x],*sts[a[x]].rbegin());
	else					st.modify(1,a[x],0);
}
inline void dfs2(int x,int f){
	dp2[x]=max(dp2[f],dp[x]);
	foreach(it,g[x]){
		int y=*it;
		if(y==f)	continue;
		dfs2(y,x);
	}
}
signed main(){
	fz(i,1,n)	a[i]=read(),key[i]=a[i];
	sort(key+1,key+n+1);
//	fz(i,1,n)	cout<<key[i]<<endl;
	fz(i,1,n)	if(key[i]!=key[i-1])	hs[++cnt]=key[i];
	fz(i,1,n)	a[i]=lower_bound(hs+1,hs+cnt+1,a[i])-hs;
//	fz(i,1,n)	cout<<a[i]<<endl;
	fz(i,1,n-1){
		int x=read(),y=read();
		g[x].push_back(y);
		g[y].push_back(x);
	}
	st.build(1,1,cnt);
	dfs(1,0);dfs2(1,0);
	fz(i,1,n)	cout<<dp2[i]<<endl;
	return 0;
}

Measured memory_bytes: 55832