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

const int inf = 1000000037;
const int maxn = 200005;

int n, from, to;
int a[maxn], lis[maxn], ans[maxn];
vector < int > g[maxn];

void dfs (int u, int p = -1) {
	int j = lower_bound(lis, lis + n, a[u]) - lis;
	int w = lis[j];
	lis[j] = a[u], ans[u] = int(lower_bound(lis, lis + n + 1, inf) - lis) - 1;
	for (int v: g[u]) {
		if (v != p)
			dfs(v, u);
	}
	lis[j] = w;
}

signed main () {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	lis[0] = -inf;
	for (int i = 1; i <= n + 1; ++i)
		lis[i] = inf;
	for (int i = 1; i < n; ++i) {
		scanf("%d %d", &from, &to);
		g[from].push_back(to);
		g[to].push_back(from);
	}
	dfs(1);
	for (int i = 1; i <= n; ++i)
		printf("%d\n", ans[i]);
}
