// ---------- begin SegmentTree Point update Range query ----------
mod segment_tree {
    pub struct PURQ<T: Clone, F: Fn(T, T) -> T> {
        n: usize,
        a: Vec<T>,
        id: T,
        op: F,
    }
    #[allow(dead_code)]
    impl<T: Clone, F: Fn(T, T) -> T> PURQ<T, F> {
        pub fn new(n: usize, id: T, op: F) -> PURQ<T, F> {
            let mut k = 1;
            while k < n {
                k *= 2;
            }
            PURQ {
                n: k,
                a: vec![id.clone(); 2 * k],
                id: id,
                op: op,
            }
        }
        pub fn update(&mut self, x: usize, v: T) {
            let mut k = self.n + x;
            let a = &mut self.a;
            a[k] = v;
            k >>= 1;
            while k > 0 {
                a[k] = (self.op)(a[2 * k].clone(), a[2 * k + 1].clone());
                k >>= 1;
            }
        }
        pub fn update_tmp(&mut self, x: usize, v: T) {
            self.a[x + self.n] = v;
        }
        pub fn update_all(&mut self) {
            for k in (1..(self.n)).rev() {
                self.a[k] = (self.op)(self.a[2 * k].clone(), self.a[2 * k + 1].clone());
            }
        }
        pub fn find(&self, mut l: usize, mut r: usize) -> T {
            let mut p = self.id.clone();
            let mut q = self.id.clone();
            l += self.n;
            r += self.n;
            while l < r {
                if (l & 1) == 1 {
                    p = (self.op)(p, self.a[l].clone());
                    l += 1;
                }
                if (r & 1) == 1 {
                    r -= 1;
                    q = (self.op)(self.a[r].clone(), q);
                }
                l >>= 1;
                r >>= 1;
            }
            (self.op)(p, q)
        }
    }
}
// ---------- end SegmentTree Point update Range query ----------

use proconio::*;
use proconio::marker::Usize1;

#[fastout]
fn run() {
    input! {
        n: usize,
        a: [u32; n],
        e: [(Usize1, Usize1); n - 1],
    }
    let mut z = a.clone();
    z.push(0);
    z.sort();
    z.dedup();
    let a: Vec<usize> = a.into_iter().map(|a| z.binary_search(&a).unwrap()).collect();
    let mut g = vec![vec![]; n];
    for (a, b) in e {
        g[a].push(b);
        g[b].push(a);
    }
    let mut seg = segment_tree::PURQ::new(z.len(), 0, |a, b| std::cmp::max(a, b));
    let mut ans = vec![0; n];
    enum Operation {
        DFS(usize, usize),
        ROLLBACK(usize, usize),
    }
    let mut stack = vec![Operation::DFS(0, 0)];// 頂点、親、命令
    while let Some(op) = stack.pop() {
        match op {
            Operation::DFS(v, p) => {
                let val = seg.find(a[v], a[v] + 1);
                stack.push(Operation::ROLLBACK(v, val));
                let l = seg.find(0, a[v]) + 1;
                seg.update(a[v], l);
                ans[v] = seg.find(0, z.len());
                for &u in g[v].iter() {
                    if u != p {
                        stack.push(Operation::DFS(u, v));
                    }
                }
            },
            Operation::ROLLBACK(v, val) => {
                seg.update(a[v], val);
            },
        }
    }
    for a in ans {
        println!("{}", a);
    }
}

fn main() {
    run();
}


Measured memory_bytes: 31728