import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdlib;

immutable int INF = 1 << 29;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;
    auto G = new int[][](N);
    foreach (i; 0..N-1) {
        auto s = readln.split.map!(to!int);
        G[s[0]-1] ~= s[1]-1;
        G[s[1]-1] ~= s[0]-1;
    }

    int[int] comp;
    auto B = A.dup.sort().uniq.array;
    foreach (i, b; B) comp[b.to!int] = i;
    foreach (ref a; A) a = comp[a];

    auto ans = new int[](N);
    auto dp = new int[](N);
    dp[] = INF;

    void dfs(int n, int p) {
        auto lb = dp.assumeSorted.lowerBound(A[n]).length.to!int;
        int prev;
        if (lb < N) {
            prev = dp[lb];
            dp[lb] = A[n];
        }
        ans[n] = dp.assumeSorted.lowerBound(INF).length.to!int;
        foreach (m; G[n]) if (m != p) {
            dfs(m, n);
        }
        if (lb < N) {
            dp[lb] = prev;
        }
    }

    dfs(0, -1);
    ans.each!writeln;
}
