#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define maxn 200005
#define inf 0x3f3f3f3f
using namespace std;
int n, from, to;
int a[maxn], dp[maxn], ans[maxn];
vector<int> edge[maxn];
void dfs(int p, int pre)
{
    int pos = lower_bound(dp, dp + n, a[p]) - dp, pp = dp[pos];
    dp[pos] = a[p];
    ans[p] = lower_bound(dp, dp + n, inf) - dp;
    for (int i : edge[p])
        if (i != pre)
            dfs(i, p);
    dp[pos] = pp;
}
int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", a + i);
    for (int i = 1; i < n; i++)
    {
        scanf("%d%d", &from, &to);
        edge[from].push_back(to);
        edge[to].push_back(from);
    }
    fill(dp, dp + n, inf);
    dfs(1, 0);
    for (int i = 1; i <= n; i++)
        printf("%d\n", ans[i]);
    return 0;
}