import java.util.*
import java.math.*
import kotlin.math.*

fun readLn()=readLine()!!
fun readInt()=readLn().toInt()
fun readInts()=readLn().split(" ").map{it.toInt()}
fun readLong()=readLn().toLong()
fun readLongs()=readLn().split(" ").map{it.toLong()}

val out=mutableListOf<String>()
fun printLine(s:String){out.add(s)}
fun output(){println(out.joinToString("\n"))}

fun Array<Int>.lower_bound(x:Int,l:Int,r:Int):Int{
    val i=this.binarySearch(x,l,r)
    if(i>=0)return i
    return -i-1
}

val N=200050
var a=IntArray(0)
val E=Array(N){ArrayList<Int>()}
val ans=Array(N){0}
val lis=Array(N){0}
var sz=0
fun DFS(u:Int,p:Int){
    var pop=false
    val i=lis.lower_bound(a[u],0,sz)
    var las=0
    if(i==sz){
        pop=true
        lis[i]=(a[u])
        sz++
    }else{
        las=lis[i]
        lis[i]=a[u]
    }
    ans[u]=sz
    for(v in E[u])if(v!=p)DFS(v,u)
    if(pop){
        sz--
    }
    else lis[i]=las
}
var pop=Array(N){false}
var las=Array(N){0}
var pos=Array(N){0}
var par=Array(N){0}

fun main(){
    val n=readInt()
    a=readInts().toIntArray()
    for(i in 1 until n){
        var (u,v)=readInts()
        E[u].add(v)
        E[v].add(u)
    }
    //DFS(0,-1)
    var stk=Stack<Int>()
    stk.push(1)
    while(!stk.isEmpty()){
        var u=stk.pop()
        if(u>0){
            pos[u]=lis.lower_bound(a[u-1],0,sz)
            if(pos[u]==sz){
                pop[u]=true
                sz++
            }
            las[u]=lis[pos[u]]
            lis[pos[u]]=a[u-1]
            stk.push(-u)
            ans[u]=sz
            for(v in E[u])if(v!=par[u]){
                par[v]=u
                stk.push(v)
            }
        }else{
            u=-u
            if(pop[u])sz--
            else lis[pos[u]]=las[u]
        }
    }
    for(i in 1..n)printLine("${ans[i]}")
    output()
}