//--------------------------------------------------
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,avx,avx2,popcnt,fma")
#pragma GCC optimize("fast-math")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Ofast")
//--------------------------------------------------
#include <bits/stdc++.h>
#include <chrono>
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <cassert>
#include <random>
#include <bitset>
#include <iomanip>
#include <numeric>
#include <time.h>
#include <ctime>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#include <stack>
#include <cstring>
//--------------------------------------------------
#define forn(i, n) for(int i = 0; i < n; i++)
#define forw(i, n) for(int i = n-1; i >= 0; --i)
#define forns(i, n, s) for(int i = s; i < n; i++)
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
//----------------------------------------------------
using namespace std;
//----------------------------------------------------
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;
typedef vector<ll> lnum;
typedef complex<ld> comp;
//----------------------------------------------------
const ll mod = 1e9 + 7, mod2 = 998244353;
const ld eps = 1e-6;
const ll inf = 1e18;
const int base = 1e9;
const ld PI = 3.1415926;
//----------------------------------------------------
#define endl '\n';
#ifdef MY_DEBUG
void deb(ld x) { cerr << x << endl; };
#else
void deb(ld x){};
#endif
//----------------------------------------------------
int n;
int a[200*1000];
vector<int> g[2*100*1000];
vector<int> ans;
//----------------------------------------------------
unsigned int bitcount(ull val) { return __builtin_popcount(val) + __builtin_popcount(val >> 32); }

void local() {
    freopen("test.in", "r", stdin);
}

void remote() {
}

void read() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n;
    forn(i, n) cin >> a[i];
    forn(i, n-1){
        int a, b;
        cin >> a >> b;
        a--;b--;
        g[a].pb(b);
        g[b].pb(a);
    }
}

int bs(const vector<stack<int>> &seq, const int &val){

    int l = -1, r = seq.size();
    while (r - l > 1){
        int m = (r+l)/2;
        if(val >= seq[m].top())
            l = m;
        else
            r = m;
    }
    return l;
}

void dfs(int v, vector<stack<int>> &seq, int p = -1){

    int pos = bs(seq, a[v]);
    if(pos == -1 || seq[pos].top() != a[v])
        pos++;

    if(pos == seq.size())
        seq.pb(stack<int>());
    seq[pos].push(a[v]);

    ans[v] = seq.size();

    for(const int &e: g[v]){
        if(e != p){
            dfs(e, seq, v);
        }
    }

    seq[pos].pop();
    if(seq.back().empty()) seq.pop_back();
}

int main() {
#ifdef MY_DEBUG
    local();
#else
    remote();
#endif
    read();

    ans.resize(n);

    vector<stack<int>> seq;
    dfs(0, seq);

    forn(i, n) {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 123080