#include <iostream>
#include <vector>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int n;
int a[200000];
vector<int> et[200000];

int INF = 1e+10;
int dp[200001];	//dp[length] = min_value
int ans[200001];
void dfs(int p, int v, int len) {
	int pos = lower_bound(dp, dp + len, a[v]) - dp;
	int tmp = dp[pos];
	int nlen = len;
	if (pos == len) { nlen = len + 1; }
	dp[pos] = a[v];
	
	ans[v] = nlen;
	int i;
	rep(i, et[v].size()) {
		int nv = et[v][i];
		if (nv == p) continue;
		dfs(v, nv, nlen);
	}
	dp[pos] = tmp;
}

signed main() {
	int i;
	
	cin >> n;
	rep(i, n) cin >> a[i];
	rep(i, n - 1) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		et[u].push_back(v);
		et[v].push_back(u);
	}
	
	rep(i, n + 1) dp[i] = INF;
	dfs(-1, 0, 0);
	rep(i, n) cout << ans[i]  << endl;
	return 0;
}
