#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

vector<int> v[200000], a, ret, tmp;
int n;

void dfs(int par, int pos){
    int len = lower_bound(tmp.begin(), tmp.end(), a[pos])-tmp.begin();
    int bef = tmp[len];
    tmp[len] = a[pos];
    ret[pos] = lower_bound(tmp.begin(), tmp.end(), 1<<30)-tmp.begin();
    for(int next : v[pos]){
        if(next == par) continue;
        dfs(pos, next);
    }
    tmp[len] = bef;
}

int main(){
    cin >> n;
    a.resize(n);
    ret.resize(n);
    tmp.resize(n+1, 1<<30);
    for(int i = 0; i < n; i++)  cin >> a[i];
    for(int i = 1; i < n; i++){
        int x, y;
        cin >> x >> y;
        x--, y--;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    dfs(-1, 0);
    for(int i = 0; i < n; i++){
        cout << ret[i] << endl;
    }
    return 0;
}
