#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

#define rep(i,N) for(int i=0; i < (int)N; i++)
#define all(v) (v).begin(),(v).end()

const int INF = 1001001001;
const int MAX_N = 200005;

vi a, ans;
vi to[MAX_N];
int dp[MAX_N];

void dfs(int v, int p=-1){
	int i = lower_bound(dp, dp+MAX_N, a[v]) -dp;
	int old = dp[i];
	dp[i] = a[v];
	ans[v] = i;
	if(p!=-1) ans[v] = max(ans[v], ans[p]);
	for(int u : to[v]){
		if(u == p) continue;
		dfs(u, v);
	}
	dp[i] = old;
}

int main(){
	int n; cin >> n;
	a = ans = vi(n); rep(i,n) cin >> a[i];

	rep(i,n-1){
		int u, v; cin >> u >> v;
		u--; v--;
		to[u].push_back(v);
		to[v].push_back(u);
	}
	fill(dp, dp+MAX_N, INF);
	dp[0] = -INF;
	dfs(0);
	rep(i,n){
		cout << ans[i] <<endl;
	}
}