#include"bits/stdc++.h"
using namespace std;
const int N=2e5+3;
int a[N],n,ans[N];
vector<int> ad[N];
multiset<int> s;
void dfs(int node,int par=-1)
{
	s.insert(a[node]);
	int del=-1;
	auto it=s.lower_bound(a[node]);
	if(++it!=s.end())
	{
		del=*it,s.erase(it);
	}
	ans[node]=s.size();
	for(auto u:ad[node])
	{
		if(u==par)continue;
		dfs(u,node);
	}
	if(del!=-1)s.insert(del);
	s.erase(s.find(a[node]));
}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
	#endif
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	int u,v;
	for(int i=1;i<n;i++)
	{
		cin>>u>>v;u--;v--;
		ad[u].push_back(v);
		ad[v].push_back(u);
	}
	dfs(0);
	for(int i=0;i<n;i++)cout<<ans[i]<<"\n";
	

}
