import java.lang.StringBuilder
import java.util.*
import kotlin.collections.ArrayList

val sc = Scanner(System.`in`)
fun nextIntArray() = sc.nextLine().split(" ").map(String::toInt).toTypedArray()

const val INF = 10000000




fun main(args: Array<String>) {

    val N = sc.nextLine().toInt()
    val a = nextIntArray()
    val map = Array(N+1){ArrayList<Int>()}
    val dp = IntArray(N){INF}
    var cnt = 0
    val ans = IntArray(N){0}

    for(i in 0..N-2){
        val u = sc.nextInt()
        val v = sc.nextInt()
        map[u].add(v)
        map[v].add(u)
    }

    val back_idx = IntArray(N+1){-1}
    val back_val = IntArray(N+1){-1}

    val stack = ArrayDeque<Int>(N)
    stack.push(1)
    while(stack.isNotEmpty()){

        var i = stack.pop()

        if(i < 0){
            i = -i
            dp[back_idx[i]] = back_val[i]
            if(back_val[i] == INF) cnt--
            continue
        }

        val s = dp.binarySearch(a[i-1], 0, cnt)
        val idx = if(s < 0) -s-1 else s

        val pre = dp[idx]
        if(pre == INF) cnt++
        dp[idx] = a[i-1]
        ans[i-1] = cnt

        stack.push(-i)
        back_idx[i] = idx
        back_val[i] = pre

        for(j in map[i]){
            if(ans[j-1] == 0) {
                stack.push(j)
            }
        }
    }

    val sb = StringBuilder()
    for(t in ans) sb.appendln(t)
    println(sb.toString())
}


