#include <stdio.h>

typedef struct List {
	struct List *next;
	int v;
} list;

int N, a[200001], ans[200001] = {}, dp[200001], flag[200001] = {};
list *adj[200001] = {}, e[400001];

void DFS(int u, int k)
{
	if (flag[u] == 1) return;
	else flag[u] = 1;
	
	int l = 0, r = k + 1, prev;
	while (l < r) {
		if (dp[(l+r)/2] < a[u]) l = (l + r) / 2 + 1;
		else r = (l + r) / 2;
	}
	ans[u] = l;
	prev = dp[l];
	dp[l] = a[u];
	
	list *p;
	for (p = adj[u]; p != NULL; p = p->next) DFS(p->v, ans[u]);
	
	dp[l] = prev;
}

int main()
{
	int i, u, w;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(a[i]));
	for (i = 0; i < N - 1; i++) {
		scanf("%d %d", &u, &w);
		e[i*2].v = w;
		e[i*2+1].v = u;
		e[i*2].next = adj[u];
		e[i*2+1].next = adj[w];
		adj[u] = &(e[i*2]);
		adj[w] = &(e[i*2+1]);
	}
	
	ans[1] = 1;
	dp[0] = 0;
	dp[1] = a[1];
	DFS(1, ans[1]);
	for (i = 1; i <= N; i++) printf("%d\n", ans[i]);
	fflush(stdout);
	return 0;
}