import std;

void calc(int[] a, int[][] adj) {
    auto dp = new int[a.length].assumeSorted;
    foreach (i; 0..a.length) dp[i] = int.max;
    auto ans = new ulong[a.length];

    void dfs(int node, int prev) {
        auto x = dp.lowerBound(a[node]);
        auto old = dp[x.length];
        dp[x.length] = a[node];

        ans[node] = x.length + 1;
        foreach (to; adj[node]) {
            if (to == prev) continue;
            dfs(to, node);
        }

        dp[x.length] = old;
    }

    dfs(0, -1);
    foreach (e; ans) writeln(e);
}

void main() {
    int n; scan(n);
    auto a = readints;
    int[][] adj;
    foreach (_; 0..n) adj ~= [[]];
    foreach (_; 0..n-1) {
        int u, v; scan(u, v);
        u--; v--;
        adj[u] ~= v;
        adj[v] ~= u;
    }
    calc(a, adj);
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;
