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

int n, a[Maxn], x, y, Ans[Maxn];
multiset<int >Rep; 
vector<int >Edge[Maxn];

inline void dfs(int u, int pre)
{
	Rep.insert(a[u]);
	auto cur = Rep.lower_bound(a[u]);
	int Keep = -1;
	if (++cur != Rep.end()) Keep = *cur, Rep.erase(cur);
	Ans[u] = Rep.size();
	
	for (auto v: Edge[u]) if (v != pre) dfs(v, u);
  
	if (Keep != -1) Rep.insert(Keep);
	Rep.erase(Rep.find(a[u]));
}

int main()
{
	scanf("%d", &n);
	for (int i=1; i<=n; i++) scanf("%d", &a[i]);
	for (int i=1; i<n; i++)
	{
		scanf("%d%d", &x, &y);
		Edge[x].push_back(y);
		Edge[y].push_back(x);
	}
	
	dfs(1, 0);
	for (int i=1; i<=n; i++) printf("%d\n", Ans[i]);
}