#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,a[200005];
vector <int> v[200005];
set <int> s;
int ans[200005];

void dfs(int x,int p) {
	auto it = s.end();
	int val,val2,ch = 0;
	if(s.empty()) s.insert(a[x]);
	else {
		it--; val = *it;
		if(a[x] > val) ch = 1,s.insert(a[x]);
		else {
			it = s.lower_bound(a[x]);
			val2 = *it;
			s.erase(it);
			s.insert(a[x]);
			ch = 2;
		}
	}
	ans[x] = s.size();
	for(int i : v[x]) {
		if(i == p) continue;
		dfs(i,x);
	}
	if(!ch) s.erase(a[x]);
	if(ch == 1) s.erase(a[x]);
	if(ch == 2) {
		s.erase(a[x]);
		s.insert(val2);
	}
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for(int i = 1;i <= n;i++) cin >> a[i];
	for(int i = 1;i < n;i++) {
		int x,y; cin >> x >> y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	dfs(1,-1);
	for(int i = 1;i <= n;i++) {
		cout << ans[i] << '\n';
	}
} 