import scala.collection.mutable
import scala.annotation.tailrec
object Main extends App {

  import scala.io.StdIn._
  val n = readInt
  val nodeValues = readLine.trim.split(' ').map(_.toInt)
  val nodes = Array.fill(n){Nil: List[Int]}
  for (_ <- 1 until n) {
    val Array(u, v) = readLine.trim.split(' ').map(_.toInt - 1)
    nodes(u) ::= v
    nodes(v) ::= u
  }
  val history = Array.fill(n){Vector[Int]()}
  history(0) = Vector(nodeValues(0))
  val result = Array.fill(n){0}
  setHistory((List(0)))
  result.foreach(println)
  @tailrec
  def setHistory(stack: List[Int]): Unit = {
    stack match {
      case Nil => ()
      case h::rest =>
        val vec = history(h)
        var left = 0
        var right = vec.length
        while (left < right) {
          val mid = (left + right) >> 1
          if (vec(mid) < nodeValues(h)) {
            left = mid + 1
          } else {
            right = mid
          }
        }
        val nextVec = if (right < vec.length) vec.updated(right, nodeValues(h)) else vec.appended(nodeValues(h))
        result(h) = nextVec.length
        var next = rest
        for (n <- nodes(h) if history(n).isEmpty) {
          next ::= n
          history(n) = nextVec
        }
        setHistory(next)
    }
  }
}