#include <iostream>
#include <cstdio>
#include <vector>
#define N 200005
using namespace std;

int n, sz, a[N], ans[N], d[N];
vector<int> gr[N];

void f(int p, int q) {
	int k, re;
	if(ans[p]) return;
	k = lower_bound(d, d+q, a[p]) - d;
	if(k == q) q++;
	ans[p] = q;
	re = d[k];
	d[k] = a[p];
	for(auto x:gr[p]) f(x, q);
	d[k] = re;
}

int main() {
	int i, t1, t2;
	cin >> n;
	for(i=1; i<=n; i++) scanf("%d", &a[i]);
	for(i=0; i<n-1; i++) {
		scanf("%d%d", &t1, &t2);
		gr[t1].push_back(t2);
		gr[t2].push_back(t1);
	}
	for(i=0; i<n; i++) d[i] = 1e9;
	f(1, 0);
	for(i=1; i<=n; i++) printf("%d\n", ans[i]);
	return 0;
}