#include<bits/stdc++.h>
using namespace std;
int n, a[200010], answer[200010];
vector<int> E[200010], vec{0};
void dfs(int u, int p) {
	int idx = -1, old = -1;
	if (a[u] > vec.back()) {
		vec.push_back(a[u]);
	} else {
		idx = lower_bound(vec.begin(), vec.end(), a[u]) - vec.begin();
		old = vec[idx];
		vec[idx] = a[u];
	}
	/*
	cout << u << " " << idx << '\n';
	for (int x : vec) {
		cout << x << " ";
	}
	cout << '\n';
	*/
	answer[u] = vec.size();
	for (int v : E[u]) {
		if (v != p) {
			dfs(v, u);
		}
	}
	if (idx == -1) {
		vec.pop_back();
	} else {
		vec[idx] = old;
	}
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	for (int i = 1; i <= n - 1; ++i) {
		int u, v;
		cin >> u >> v;
		E[u].push_back(v);
		E[v].push_back(u);
	}
	dfs(1, 1);
	for (int i = 1; i <= n; ++i) {
		cout << answer[i] - 1 << '\n';
	}
}