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

const int N = 2e5;
vector<int>ele;
int a[N+100],ans[N+100];
vector<int>g[N+100];

void dfs(int v,int par,int cur)
{
	auto in = lower_bound(ele.begin(),ele.end(),a[v])-ele.begin();
	int pre = ele[in];
	if(in==cur){
		cur++;
	}
	ele[in] = a[v];
	ans[v] = cur;
	for(auto it:g[v])
	{
		if(it!=par){
			dfs(it,v,cur);
		}
	}
	ele[in] = pre;
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",a+i);
	}
	for(int i=1;i<n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	for(int i=1;i<=n+100;i++){
		ele.push_back(1e9+1);
	}
	dfs(1,0,0);
	for(int i=1;i<=n;i++){
		printf("%d\n",ans[i]);
	}
}
