#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
template <typename Set>
struct Monoid
{
    using Op = function<Set(Set, Set)>;
    const Op f;
    const Set e;
    Monoid(const Op F, const Set E) : f(F), e(E)
    {
    }
};
template <typename Set>
struct SegmentTree
{
    using Op = function<Set(Set, Set)>;
    Monoid<Set> M;
    Set e;
    int size; //一番下以外の区間たち全部の数
    vector<Set> seg;
    SegmentTree(int n, const Monoid<Set> &M) : M(M)
    {
        size = 1;
        while (size < n)
        {
            size <<= 1;
        }
        e = M.e;
        seg.assign(2 * size, e);
    }
    void set(int k, const Set &x)
    {
        seg[k + size] = x;
    }
    void build()
    {
        for (int k = size - 1; k > 0; k--)
        {
            seg[k] = M.f(seg[2 * k + 0], seg[2 * k + 1]);
        }
    }
    void update(int k, const Set &x)
    {
        k += size;
        seg[k] = x;
        while (k >>= 1)
        {
            seg[k] = M.f(seg[2 * k + 0], seg[2 * k + 1]);
        }
    }
    Set query(int a, int b) //区間[a,b)に対して演算したやつを返す
    {
        Set L = e, R = e;
        for (a += size, b += size; a < b; a >>= 1, b >>= 1) //ループ一回ごとにa,bは親に向かう
        {
            if (a & 1) //a%2==1なら
            {
                L = M.f(L, seg[a++]);
            }
            if (b & 1)
            {
                R = M.f(seg[--b], R);
            }
        }
        return M.f(L, R);
    }
};
vector<int> zaatu(vector<long long> a)
{
    auto tmp = a;
    sort(tmp.begin(), tmp.end());
    tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end());
    int n = a.size();
    vector<int> res(n);
    for (size_t i = 0; i < n; i++)
    {
        int id = lower_bound(tmp.begin(), tmp.end(), a[i]) - tmp.begin();
        res[i] = id;
    }
    return res;
}
const int MAX_N = 2 * 100000 + 1;
vvint graph(MAX_N);
int N;
Monoid<int> M([](int a, int b) { return max(a, b); }, 0);
SegmentTree<int> dp(MAX_N, M);
vint p(MAX_N), ans(MAX_N);
stack<int> s;
void dfs(int i, int par)
{
    int A = dp.query(0, p[i]) + 1;
    ans[i] = A;
    int now = dp.query(p[i], p[i] + 1);
    dp.update(p[i], A);
    for (auto &&j : graph[i])
    {
        if (j != par)
        {
            dfs(j, i);
        }
    }
    dp.update(p[i], now);
}
void dfs2(int i, int par)
{
    if (par != -1)
        chmax(ans[i], ans[par]);
    for (auto &&j : graph[i])
    {
        if (j != par)
            dfs2(j, i);
    }
}
int main()
{

    cin >> N;
    vll a(N);
    for (size_t i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    p = zaatu(a);
    int u, v;
    for (size_t i = 0; i < N - 1; i++)
    {
        cin >> u >> v;
        u--;
        v--;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
    //    dp.update(0, 1);
    dfs(0, -1);
    dfs2(0, -1);
    for (size_t i = 0; i < N; i++)
    {
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 50812