#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


// range query using segment tree
#define ISMAXRANGE	1		// 1 = max range, 0 = min range
#define VERYBIG		200000000	


class segment_tree {
	vector<long long> t;
	long size;
public:
	segment_tree(long n) {
		if (ISMAXRANGE) t.assign(4 * n + 1, 0);
		else t.assign(4 * n + 1, VERYBIG);
		size = n;
	}

	void initialize_array(vector<long long>& v) {
		initialize_with_array(1, 0, size - 1, v);
	}

	void initialize_with_array(long startpos, long l, long r, vector<long long>& v) {
		if (l == r) {
			t[startpos] = v[l];
		}
		else {
			long m = (l + r) / 2;
			initialize_with_array(2 * startpos, l, m, v);
			initialize_with_array(2 * startpos + 1, m + 1, r, v);

			if (ISMAXRANGE == 1) t[startpos] = max(t[startpos * 2], t[startpos * 2 + 1]);
			else  t[startpos] = min(t[startpos * 2], t[startpos * 2 + 1]);
		}
	}

	void update(long index, long long val) { // insert val into location index
		update_full(1, 0, size - 1, index, val);
	}

	void update_full(long startpos, long l, long r, long index, long long val) {
		if (l == r) {
			t[startpos] = val;
		}
		else {
			long m = (l + r) / 2;
			if (index <= m) update_full(2 * startpos, l, m, index, val);
			else update_full(2 * startpos + 1, m + 1, r, index, val);

			if (ISMAXRANGE) t[startpos] = max(t[startpos * 2], t[startpos * 2 + 1]);
			else t[startpos] = min(t[startpos * 2], t[startpos * 2 + 1]);
		}
	}

	long long query(long l, long r) {  // get range min/max between l and r
		if (l > r) {
			if (ISMAXRANGE) return 0;
			else return VERYBIG;
		}
		return query_full(1, 0, size - 1, l, r);
	}

	long long query_full(long startpos, long left, long right, long l, long r) {	 // left/right = current range, l/r = intended query range
		if ((left >= l) && (right <= r)) return t[startpos];
		long m = (left + right) / 2;
		long long ans;
		if (ISMAXRANGE) ans = -(1LL << 60);
		else ans = VERYBIG;
		if (m >= l) {
			if (ISMAXRANGE) ans = max(ans, query_full(startpos * 2, left, m, l, r));
			else ans = min(ans, query_full(startpos * 2, left, m, l, r));
		}
		if (m + 1 <= r) {
			if (ISMAXRANGE) ans = max(ans, query_full(startpos * 2 + 1, m + 1, right, l, r));
			else ans = min(ans, query_full(startpos * 2 + 1, m + 1, right, l, r));
		}
		return ans;
	}
};

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	//freopen("cat.txt", "r", stdin); // redirects standard input

	long long n, i, j, k, ct, a, b, level;
	cin >> n;

	vector<vector<int>> adj(n + 1);
	vector<int> parent(n + 1, -1), v(n + 1), ans(n + 1, 1), dp(n + 1, 0), curr(n + 1, 0), bestans(n + 1, 0), old(n + 1, 0), c(n + 1, 0);

	set<int> s;
	map<int, int> id;
	for (i = 1; i <= n; i++) {
		cin >> v[i];
		s.insert(v[i]);
	}
	ct = 1;
	for (auto p : s) id[p] = ct++;
	for (i = 1; i <= n; i++) v[i] = id[v[i]];

	for (i = 0; i < n - 1; i++) {
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}

	parent[1] = 0;
	stack<int> stt;
	segment_tree st(n + 1);
	level = -1;
	stt.push(1);

	while (!stt.empty()) {
		level = stt.size() - 1;
		int iid = stt.top();
		if (c[level] == 0) {
			old[level] = dp[v[iid]];
			curr[level] = max(1LL, st.query(0, v[iid] - 1) + 1);
			bestans[level] = max(bestans[level], curr[level]);
			ans[iid] = bestans[level];
			if (curr[level] > old[level]) {
				dp[v[iid]] = curr[level];
				st.update(v[iid], curr[level]);
			}
		}
		if (c[level] >= adj[iid].size()) {
			st.update(v[iid], old[level]);
			dp[v[iid]] = old[level];

			c[level] = 0;
			old[level] = 0;
			curr[level] = 0;
			bestans[level] = 0;
			stt.pop();
		}
		int p = adj[iid][c[level]];
		c[level]++;

		if (parent[p] == -1) {
			parent[p] = iid;
			bestans[level + 1] = bestans[level];
			stt.push(p);
			c[level + 1] = 0;
		}
	}

	for (i = 1; i <= n; i++) cout << ans[i] << "\n";


	return 0;
}


Measured memory_bytes: 45984