#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
#define pr std::pair<int,int>
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
template<class T>void cxk(T&a,T b){a=a>b?a:b;}
template<class T>void cnk(T&a,T b){a=a<b?a:b;}
#ifdef mod
int pow(int x,int y){
	int ret=1;
	while(y){
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;y>>=1;
	}
	return ret;
}
template<class Ta,class Tb>void inc(Ta&a,Tb b){a=a+b>=mod?a+b-mod:a+b;}
template<class Ta,class Tb>void dec(Ta&a,Tb b){a=a>=b?a-b:a+mod-b;}
#endif
int W[200010],fir[200010],dis[400010],nxt[400010],id;
void link(int a,int b){nxt[++id]=fir[a],fir[a]=id,dis[id]=b;}
int ans[200010],max[200010],c;
void DFS(int x,int fa=-1){
	ans[x]=std::upper_bound(max,max+c+1,W[x])-max;
	int _=-1;
	if(ans[x]>c)max[++c]=W[x];
	else _=max[ans[x]],cnk(max[ans[x]],W[x]);
	for(int i=fir[x];i;i=nxt[i]){
		if(dis[i]==fa)continue;
		DFS(dis[i],x);
	}
	if(~_)max[ans[x]]=_;
	else--c;
}
int main(){
#ifdef LOCAL
	freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);
#endif
	int n=gi(),a,b;
	for(int i=1;i<=n;++i)W[i]=gi();
	for(int i=1;i<n;++i)a=gi(),b=gi(),link(a,b),link(b,a);
	DFS(1);for(int i=1;i<=n;++i)printf("%d\n",ans[i]);
	return 0;
}

