#include <bits/stdc++.h>
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater(){
    #ifndef ONLINE_JUDGE
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
    #endif
}
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a,v) memset(a, v, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=1e9+7;
const int N=2e5+5;
int n;
int a[N];
vector<int> g[N];
int dp[N];
vector<int> c(N,0);
int sz=0;
int ans[N];
void dfs(int i,int p){
    int f=0;
    int x,y;
    if(c[1]>=a[i]){
        f=1;
        x=c[1];
        c[1]=a[i];
        dp[i]=1;
    }
    else if(a[i]>c[sz]){
        f=2;
        sz++;
        x=c[sz];
        c[sz]=a[i];
        dp[i]=sz;
    }
    else{
        f=3;
        int k=lower_bound(c.begin()+1,c.begin()+sz,a[i])-c.begin();
        y=k;
        x=c[k];
        c[k]=a[i];
        dp[i]=k;
    }
    ans[i]=dp[i];
    if(p!=-1){
        ans[i]=max(ans[i],ans[p]);
    }
    for(auto j:g[i]){
        if(j==p)continue;
        dfs(j,i);
    } 
    if(f==1){
        c[1]=x;
    }
    if(f==2){
        c[sz]=x;
        sz--;
    }
    if(f==3){
        c[y]=x;
    }
}
int main() {
   
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int T=1;
    // cin>>T;
    while(T--){
        cin>>n; 
        rep(i,n)cin>>a[i+1];
        rep(i,n-1){
            int x,y;cin>>y>>x;
            g[x].pb(y);
            g[y].pb(x);
        }
        dfs(1,-1);
        repA(i,1,n){
            cout<<ans[i]<<endl;
        }
    }   
    timecalculater();
    return 0;   
} 


Measured memory_bytes: 31704