#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os << "[ "; 
	for(auto v:V)os << v << " "; return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){ os << "{ "; 
	for(auto s:S) os<<s<<" ";  return os<<"}"; 
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
	return os<<"("<<P.first<<","<< P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
	os<<"{ ";for(auto m:M)os<<"("<<m.F<<":"<<m.S<<")";
	return os<<"}";
}
#define cerr cout
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define I insert 
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define For(i,n) for(int i=0;i<(int)n;++i)
#define Rev(i,n) for(int i=(int)n-1;i>=0;--i)
#define Rep(i,n) for(int i=1;i<=(int)n;++i)
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpii;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

const int N = 2e5 + 100;

int A[N];
vi G[N];
int ans[N];
vector<int> inc;

void dfs(int s , int p){
	if(inc.size() == 0){
		ans[s] = 1;
		inc.pb(A[s]);
		for(auto it : G[s]){
			if(it == p) continue;
			dfs(it , s);
		}
	}
	else{
		int type = 0;
		int idx , val;
		if(A[s] < inc[0]){
			idx = 0;
			val = inc[0];
			inc[0] = A[s];
		}
		else if(A[s] > inc.back()){
			inc.pb(A[s]);
			type = 1;
		}
		else{
			int lo = 0 , hi = inc.size()-1 , ans = lo;
			while(lo <= hi){
				int mid = (lo+hi)>>1;
				if(inc[mid] < A[s]){
					ans = mid;
					lo = mid+1;
				}
				else{
					hi = mid-1;
				}
			}
			idx = ans+1;
			val = inc[ans+1];
			inc[ans+1] = A[s];
		}
		ans[s] = inc.size();
		for(auto it : G[s]){
			if(it == p) continue;
			dfs(it , s);
		}
		if(type == 1){
			inc.pop_back();
		}
		else{
			inc[idx] = val;
		}
	}

}


int main(){
	fio; cout<<fixed<<setprecision(25);	
	int n; cin >> n;
	for(int i = 1;i <= n ; ++i)
		cin >> A[i];
	int u , v;
	for(int i= 0;i < n-1 ; ++i){
		cin >> u >> v;
		G[u].pb(v);
		G[v].pb(u);
	}	
	// inc.pb(A[1]);
	dfs(1 , -1);
	for(int i =1 ;i <= n ; ++i)
		cout << ans[i] << endl;








	return 0;
}
