use std::io::{self, BufRead, Write};

struct IO<'a> {
    reader: io::BufReader<io::StdinLock<'a>>,
    writer: io::BufWriter<io::StdoutLock<'a>>,
}

impl<'a> IO<'a> {
    fn new(stdin: &'a io::Stdin, stdout: &'a io::Stdout) -> IO<'a> {
        let reader = io::BufReader::new(stdin.lock());
        let writer = io::BufWriter::new(stdout.lock());
        IO { reader, writer }
    }

    fn read_line(&mut self) -> String {
        let mut buf = String::new();
        self.reader.read_line(&mut buf).unwrap();
        buf
    }

    fn in_1<T: std::str::FromStr>(&mut self) -> T {
        let buf = self.read_line();
        buf.trim_end().parse().ok().unwrap()
    }

    fn in_2<T, U>(&mut self) -> (T, U)
        where T: std::str::FromStr, U: std::str::FromStr
    {
        let buf = self.read_line();
        let mut iter = buf.split_whitespace();
        (
            iter.next().unwrap().parse().ok().unwrap(),
            iter.next().unwrap().parse().ok().unwrap(),
        )
    }

    fn in_v<T: std::str::FromStr>(&mut self) -> Vec<T> {
        let buf = self.read_line();
        let iter = buf.split_whitespace();
        iter.map(|x| x.parse().ok().unwrap()).collect()
    }

    fn out<T: std::fmt::Display>(&mut self, ans: T) {
        writeln!(self.writer, "{}", ans).unwrap();
    }
}

const INF: i32 = 1 << 30;

struct DFS {
    n: usize,
    a: Vec<i32>,
    g: Vec<Vec<usize>>,
    seen: Vec<bool>,
    dp: Vec<i32>,
    ans: Vec<String>,
}

impl DFS {
    fn new(n: usize, a: Vec<i32>, g: Vec<Vec<usize>>) -> DFS {
        DFS {
            n, a, g,
            seen: vec![false; n],
            dp: vec![INF; n],
            ans: vec![String::new(); n],
        }
    }

    fn search(&mut self, from: usize) {
        self.seen[from] = true;
        let i = {
            let (mut left, mut right) = (0, self.n);
            while left < right {
                let mid = (left + right) / 2;
                if self.dp[mid] < self.a[from] {
                    left = mid + 1;
                } else {
                    right = mid;
                }
            }
            left
        };
        let tmp = self.dp[i];
        self.dp[i] = self.a[from];
        let j = {
            let (mut left, mut right) = (0, self.n);
            while left < right {
                let mid = (left + right) / 2;
                if self.dp[mid] < INF {
                    left = mid + 1;
                } else {
                    right = mid;
                }
            }
            left
        };
        self.ans[from] = j.to_string();
        for to in self.g[from].clone() {
            if self.seen[to] { continue; }
            self.search(to);
        }
        self.dp[i] = tmp;
    }
}

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    let mut io = IO::new(&stdin, &stdout);

    let n: usize = io.in_1();
    let a: Vec<i32> = io.in_v();
    let mut g: Vec<Vec<usize>> = vec![vec![]; n];
    for _ in 0..(n - 1) {
        let (u, v): (usize, usize) = {
            let (u, v): (usize, usize) = io.in_2();
            (u - 1, v - 1)
        };
        g[u].push(v);
        g[v].push(u);
    }

    let mut dfs = DFS::new(n, a, g);
    dfs.search(0);
    io.out(dfs.ans.join("\n"));
}

Measured memory_bytes: 63380