#include <bits/stdc++.h>
//#define inf 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define inv(x) Power(x, mod - 2)
#define fi first
#define se second
#define MP make_pair
#define PB push_back

using namespace std;
typedef pair<int,int> Pair;
typedef long double ld;
typedef long long ll;

const int mod = 998244353, MAX = 1e5, N = 2000005;
//template{{{
const long double Pi = 3.14159265358979323846l;
inline int add(int x, int y) { x += y; return x >= mod ? x - mod : x; };
inline void inc(int &x, int y) { x += y; x -= (x >= mod ? mod : 0); }
inline int mul(int x, int y) { return 1ll * x * y % mod; }
inline int Power(int x, int y) {
	int ans = 1;
	while (y) {
		if (y & 1) ans = mul(ans, x);
		x = mul(x, x), y >>= 1;
	} return ans;
}

/*char buf[1<<23],obuf[1<<23],*p1=buf,*p2=buf, *O = obuf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
void print(int x) {
    if(x > 9) print(x / 10);
    *O++=x%10+'0';
} */

template <class T> inline T	input() {
	T x; char ch; bool flag = false;
	while (!isdigit(ch = getchar())) flag |= ch == '-';
	for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48));
	return flag ? -x : x;
}

template <class T> inline bool chkmin(T &x, T y) { x = x < y ? x : y; return x == y; }
template <class T> inline bool chkmax(T &x, T y) { x = x > y ? x : y; return x == y; }
template <class T> inline T gcd(T x, T y) { return !y ? x : gcd(y, x % y); }
template <class T> inline T sqrm(T x) { return (ll) x * x % mod; }
template <class T> inline T sqr(T x) { return x * x; }

struct {
	inline operator int () { return input<int>(); }
	inline operator long long () { return input<long long>(); }
	template <class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read; //}}}

#define int ll
int n;
int b[N];
int a[N], ans[N];
vector<int> T[N];

int Max[N << 2];

#define mid ((l + r) >> 1)
#define ls rt << 1
#define rs rt << 1 | 1

void change(int rt, int l, int r, int p, int v) {
	if (l == r) return Max[rt] = v, void();
	if (p <= mid) change(ls, l, mid, p, v);
	else change(rs, mid + 1, r, p, v);
	Max[rt] = max(Max[ls], Max[rs]);
}

int query(int rt, int l, int r, int L, int R) {
	if (L > R) return 0;
	if (L <= l && r <= R) return Max[rt];
	int res = 0;
	if (L <= mid) chkmax(res, query(ls, l, mid, L, R));
	if (R > mid) chkmax(res, query(rs, mid + 1, r, L, R));
	return res;
}

void AddEdge(int x, int y) {
	T[x].push_back(y);
	T[y].push_back(x);
}

void dfs(int u, int fa) {
	int tmp = query(1, 1, n, a[u], a[u]);
	ans[u] = max(tmp, query(1, 1, n, 1, a[u] - 1) + 1);
	change(1, 1, n, a[u], ans[u]);
	chkmax(ans[u], query(1, 1, n, 1, n));

	for (int v : T[u]) {
		if (v == fa) continue;
		dfs(v, u);
	}

	change(1, 1, n, a[u], tmp);
}

signed main() {
#ifdef local
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	freopen("log", "w", stderr);
#endif

	read(n);
	for (int i = 1; i <= n; ++i) b[i] = a[i] = read;
	for (int i = 1; i < n; ++i) AddEdge(int(read), int(read));

	sort(b + 1, b + n + 1);
	for (int i = 1; i <= n; ++i)
		a[i] = lower_bound(b + 1, b + n + 1, a[i]) - b;

	dfs(1, 0);

	for (int i = 1; i <= n; ++i)
		printf("%lld\n", ans[i]);
	return 0;
}


Measured memory_bytes: 76848