#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#include <numeric>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define nmax_def 220000
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

class Graph_class {
public:
	bool graph_from1 = true;
	bool graph_tree = true;
	bool graph_weight = false;
	bool graph_digraph = false;
	int N, M;
	vector<pii> edgelist;
	vl edgeweight;
	vector<vi> adjlist;
	vector<vl> adjlistweight;
	vi adjnum;
	map<pii, int> uv_to_edge;

	vi adj_to_root;
	vector<ll> DP;
	vi vlist_from_root;
	vl xdist;

	vb x_visited;
	deque<int> x_que;

	// -------
	vl A;
	vl update_i;
	vl update_val;
	vl ans;
	// -------

	void read_edge();
	void adjini();
	void visited_ini();
	void graph_DFS_sbrt(ll DFS_ini);
	void solve();

	bool xydist_def = false;
};

// ----- graph -----

void Graph_class::read_edge() {
	cin >> N;
	if (graph_tree)
		M = N - 1;// graph
	else
		cin >> M;
	A.resize(N);
	update_i.resize(N);
	update_val.resize(N);
	ans.resize(N);
	DP.resize(N + 1, InfLL);
	rep(i, N)
		cin >> A[i];
	edgelist.resize(M);
	edgeweight.resize(M, 1);
	rep(i, M) {
		if (graph_weight)
			cin >> edgelist[i].first >> edgelist[i].second >> edgeweight[i];
		else
			cin >> edgelist[i].first >> edgelist[i].second;
		if (graph_from1) {
			edgelist[i].first--;
			edgelist[i].second--;
		}
		//uv_to_edge[edgelist[i]] = i;
	}
	return;
}

void Graph_class::adjini() {
	adjnum.resize(N);
	xdist.resize(N, -1);
	adjlist.resize(N);
	adjlistweight.resize(N);
	adj_to_root.resize(N, -1);
	rep(i, N)
		adjnum[i] = 0;
	rep(i, M) {
		int x = edgelist[i].first;
		int y = edgelist[i].second;
		ll xyweight = edgeweight[i];
		adjlist[x].push_back(y);
		adjlistweight[x].push_back(xyweight);
		adjnum[x]++;
		if (!graph_digraph) {
			adjlist[y].push_back(x);
			adjlistweight[y].push_back(xyweight);
			adjnum[y]++;
		}
	}
	x_visited.resize(N);
	visited_ini();

	return;
}

void Graph_class::visited_ini() {
	rep(i, N) {
		x_visited[i] = false;
		adj_to_root[i] = -1;
	}
	x_que.clear();
}

void Graph_class::graph_DFS_sbrt(ll DFS_ini) {
	x_visited[DFS_ini] = true;

	// in (更新)
	update_i[DFS_ini] = lower_bound(DP.begin(), DP.end(), A[DFS_ini]) - DP.begin();
	update_val[DFS_ini] = *lower_bound(DP.begin(), DP.end(), A[DFS_ini]);
	*lower_bound(DP.begin(), DP.end(), A[DFS_ini]) = A[DFS_ini];
	ans[DFS_ini] = lower_bound(DP.begin(), DP.end(), InfLL) - DP.begin();

	rep(i, adjnum[DFS_ini]) {
		int x_new = adjlist[DFS_ini][i];
		if (!x_visited[x_new]) {
			x_visited[x_new] = true;
			graph_DFS_sbrt(x_new);
		}
	}

	// out (復元)
	DP[update_i[DFS_ini]] = update_val[DFS_ini];

	return;
}

void Graph_class::solve() {
	graph_DFS_sbrt(0);
	rep(i, N)
		cout << ans[i] << endl;
	return;
}

int main(void) {
	Graph_class graph;
	graph.read_edge();
	graph.adjini();
	graph.solve();
	return 0;
}

Measured memory_bytes: 50356