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

const int nm = 2e5;
int n, a[nm], ans[nm], dp[nm + 1], am = 1e9;
vector<int> g[nm];
void dfs(int v, int p, int l) {
	int inf = 0, sup = l + 1;
	while (sup - inf > 1) {
		int mid = (inf + sup) / 2;
		if (dp[mid] >= a[v])
			sup = mid;
		else
			inf = mid;
	}
	int prev = dp[sup];
	dp[sup] = a[v];
	ans[v] = max(sup, l);
	for (int nv : g[v]) {
		if (nv == p)
			continue;
		dfs(nv, v, ans[v]);
	}
	dp[sup] = prev;
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0, u, v; i < n - 1; i++) {
		cin >> u >> v;
		u--, v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	for (int i = 1; i <= n + 1; i++)
		dp[i] = 1e9 + 1;
	dfs(0, -1, 0);
	for (int i = 0; i < n; i++)
		cout << ans[i] << endl;
}
