/** 	Author: Apoorva Mittal  **/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define vi vector<int>
#define vvi vector<vector<int>>
#define vii vector<pair<int, int>>
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repD(i, a, b) for (int i = a; i >= b; i--)
#define speed                     \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define init(i, k) memset(i, k, sizeof i)
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define inp(a) rep(i, 0, (int)a.size()) cin >> a[i];
//--------------------------------------------debugging showoff---------------------------------------------------------
#define out(a)                               \
    cout << #a << ": " << endl;              \
    rep(i, 0, a.size()) cout << a[i] << " "; \
    cout << endl;
#define out2d(a)                \
    cout << #a << ": " << endl; \
    rep(i, 0, a.size())         \
    {                           \
        rep(j, 0, a[0].size())  \
                cout            \
            << a[i][j] << " ";  \
        cout << endl;           \
    }
#define sim template <class c
#define ris return *this
#define dor > deb &operator<<
#define eni(x)                                                                  \
    sim > typename enable_if<sizeof dud<c>(0) x 1, deb &>::type operator<<(c i) \
    {
sim > struct rge
{
    c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct deb
{
#ifdef LOCAL
    ~deb()
    {
        cerr << endl;
    }
    eni(!=) cerr << boolalpha << i;
    ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
    sim dor(const c &)
    {
        ris;
    }
#endif
}
;
#define cv(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
// -DLOCAL
//--------------------------------------------useless stuff---------------------------------------------------------------------
#define flush fflush(stdout);
#define lb lower_bound
#define ub upper_bound
#define maxe *max_element
#define mine *min_element
#define umap unordered_map
#define uset unordered_set
#define mset multiset
#define pqueue priority_queue
#define precise(x) cout << fixed << showpoint << setprecision(x);
#define setbit(x) __builtin_popcountll(x)
#define gcd(a, b) __gcd(a, b)
//------------------------------------------------------------------------------------------------------------------------------
const int mod = 1e9 + 7;
// ====== Useful functions begin ======
inline int add(int a, int b) { return ((a % mod) + (b % mod)) % mod; }
inline int sub(int a, int b) { return ((a % mod) - (b % mod) + mod) % mod; }
inline int mul(int a, int b) { return ((a % mod) * (b % mod)) % mod; }
// ====== Useful functions end ======
//--------------------------------------------------------------------------------------------------------------------------------
const int inf = 1e18;
const int maxn = 1e3 + 5;
//--------------------------------------------------------------------------------------------------------------------------------
vector<vector<int>> g;
vector<int> len;
vector<int> arr;
void dfs(int u, vi &lis, int p)
{

    int idx = lb(all(lis), arr[u]) - lis.begin();
    //deb() << cv(u + 1) cv(lis);
    int temp=-1;
    if(idx == lis.size())
    {
        lis.pb(arr[u]);
    }
    else{   
        temp = lis[idx];
        lis[idx] = arr[u];
    }
    len[u] = lis.size(); 
    for (auto v : g[u])
    {
        if(v==p) continue;
        dfs(v, lis, u);
    }

    //deb() << cv(u + 1) cv(lis);
    if(temp==-1) lis.pop_back();
    else lis[idx] = temp;

}
void solve()
{
    int n;
    cin >> n;

    arr = vector<int>(n);
    inp(arr);

    int m = n - 1;
    g = vector<vector<int>>(n);
    len = vector<int>(n);
    while (m--)
    {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        g[u].pb(v);
        g[v].pb(u);
    }
    vector<int> lis;

    lis.pb(arr[0]);
    len[0] = 1;

    for (int v : g[0])
    {
        dfs(v, lis,0);
    }

    for (int i = 0; i < n; i++)
    {
        cout << len[i] << endl;
    }
}
signed main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    speed;
    int t = 1;
    // cin >> t;

    for (int tt = 1; tt <= t; tt++)
    {
        // cout<<"Case #"<<tt<<": ";
        solve();
    }
}


Measured memory_bytes: 31616