/*
    Mbak Sana Dong
    Mbak Chaeyoung Dong
*/
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int arr[200200];
int segtree[600600];
int cnt[200200];
vector<int> vi[200200];
vector<int> va;
int sana[200200];
void update(int idx, int l, int r, int id, int val)
{
    if(id < l || id > r) return;
    if(l == r && l == id) {
        segtree[idx] = val;
        return;
    }
    int mid = (l+r) / 2;
    update(idx*2, l, mid, id, val);
    update(idx*2+1, mid+1, r, id, val);
    segtree[idx] = max(segtree[idx*2], segtree[idx*2+1]);
}
int query(int idx, int l, int r, int kiri, int kanan)
{
    if(l > kanan || r < kiri) return 0;
    if(l >= kiri && r <= kanan) return segtree[idx];
    int mid = (l+r) / 2;
    int curr = 0;
    curr = max(curr, query(idx*2, l, mid, kiri, kanan));
    curr = max(curr, query(idx*2+1, mid+1, r, kiri, kanan));
    return curr;
}
const int N = 2e5;
void dfs(int now, int prev)
{
    int last = query(1, 1, N, arr[now], arr[now]);
    int curr = query(1, 1, N, 1, arr[now] - 1);
    curr++;
    update(1, 1, N, arr[now], curr);
    sana[now] = curr;
    for(auto x : vi[now])
    {
        if(x == prev) continue;
        dfs(x, now);
    }
    update(1, 1, N, arr[now], last);
}
int main()
{
	int n,i,j,k,x,y,ans,curr,temp,m;
	int tc;
	cin >> n;
	for(i=1;i<=n;i++)
    {
        scanf("%d",&arr[i]);
        va.push_back(arr[i]);
    }
    sort(va.begin(), va.end());
    for(i=1;i<=n;i++)
    {
        arr[i] = lower_bound(va.begin(), va.end(), arr[i]) - va.begin();
        arr[i]++;
        cout << arr[i] << " ";
    }
    cout << endl;
    for(i=1;i<n;i++)
    {
        cin >> x >> y;
        vi[x].push_back(y);
        vi[y].push_back(x);
    }
    dfs(1, 0);
    for(i=1;i<=n;i++) cout << sana[i] << endl;
	return 0;
}
