// skip until line 65
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <sstream>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

#define BR "\n"
#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a, b) ((((a) % (b) ) + (b)) % (b))
#define FEACH(it, cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it, cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define MAX(V, T) V=max(V,T)
#define MIN(V, T) V=min(V,T)

#define DumpArray(cont, from, to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i]<<")";} cout<<endl;

/*
 * ***_bound(6)
 * 5 6 6 6 6 6 7 7 7
 *   ^lower    ^upper
 * void reverse(c.begin(), c.end())
 *
 * graph
 * seg tree
 * dp
 * brute force
 */
struct Comparator{
    int operator()(int l, int r) const {
        return r<l;
    }
};
struct Vec{
    double v[2];
    string to_s(){
        return "("+to_string(v[0])+","+to_string(v[1])+")";
    }
    double& operator[](int t){
        return v[t];
    }
    Vec operator+(Vec t) {
        return {v[0]+t[0],v[1]+t[1]};
    }
    Vec& operator+=(Vec t) {
        v[0]+=t[0];v[1]+=t[1];
        return *this;
    }
    Vec operator-(Vec t) {
        return {v[0]-t[0],v[1]-t[1]};
    }
    Vec& operator-=(Vec t) {
        v[0]-=t[0];v[1]-=t[1];
        return *this;
    }
    Vec operator*(double t) {
        return {v[0]*t,v[1]*t};
    }
    Vec& operator*=(double t) {
        v[0]*=t;v[1]*=t;
        return *this;
    }
    double operator*(Vec t) {
        return v[0]*t[0]+v[1]*t[1];
    }
    Vec operator-(){
        return {-v[0],-v[1]};
    }
    static Vec Z;
};
Vec Vec::Z={0,0};
//set<int, Comparator> S;

// solution below
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;

struct SegmentTree {
    vector<stack<int>> Storage;
    int N;
    void init(int n) {
        N=1;
        while(N<n) N*=2;
        Storage.resize(N*2);
        for(int i=0;i<N*2;++i) {
            Storage[i].push(0);// XXX: Can need change
        }
    }

    void pushValue(int i, int value) {
        i += N-1;
        Storage[i].push(value);
        while(i>0) {
            i = (i-1) / 2;
            Storage[i].push(max(Storage[i*2+1].top(),Storage[i*2+2].top()));
        }
    }

    void popValue(int i) {
        i += N-1;
        Storage[i].pop();
        while(i>0) {
            i = (i-1) / 2;
            Storage[i].pop();
        }
    }

    int calcRange(int a,int b,int k,int l, int r) {
        if(b<=l || a>=r) return 0;// XXX: Can need change
        if(a<=l && b>=r) {
            return Storage[k].top();
        } else {
            int tl = calcRange(a,b,k*2+1,l,(l+r)/2);
            int tr = calcRange(a,b,k*2+2,(l+r)/2,r);
            return max(tl,tr);
        }
    }

    int calcRange(int a,int b){
        return calcRange(a,b,0,0,N);
    }

    void printAll() {
        for(int i=0;i<N*2-1;++i) {
            if( ((i + 1) & i)  == 0) printf("\n");
            printf("%d ",Storage[i].top());
        }
    }

    void test() {
        while(true) {
            int l,r;
            scanf("%d%d", &l,&r);
            printf("%d\n",calcRange(l,r,0,0,N));
        }
    }

};

SegmentTree seg;
vector<bool> Visited;
vector<int> Ans;

int N;
vector<int> A;
vector<vector<int>> G;
void dfs(int c) {
    Visited[c]=true;
    int a=seg.calcRange(0,A[c])+1;
    int o=seg.calcRange(A[c],A[c]+1);
    seg.pushValue(A[c],max(o,a));
    Ans[c]=seg.calcRange(0,N+5);
    for(int v:G[c]) {
        if (!Visited[v]) {
            dfs(v);
        }
    }
    seg.popValue(A[c]);
}
int main() {
    cin >> N;
    A.resize(N,0);
    Ans.resize(N);
    Visited.resize(N,false);
    seg.init(N+10);
    G.resize(N);
    REP(i,N)
        cin>>A[i];
    // tood: normalize
    {
        map<int,int> Dict;
        vector<int> B=A;
        sort(ALL(B));
        Dict.insert({B[0],0});
        int c=0;
        for(int i=1;i<N;++i) {
            if (B[i]!=B[i-1])c++;
            Dict.insert({B[i],c});
        }
        REP(i,N)
            A[i]=Dict[A[i]];
    }
    REP(i,N-1) {
        int u,v;
        cin >>u >>v;--u;--v;
        G[u].pb(v);
        G[v].pb(u);
    }
    dfs(0);
    REP(i,N){
        cout<<Ans[i]<<endl;
    }
}


Measured memory_bytes: 401872