import java.util.Stack

fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val a = readLine()!!.split(" ").map { it.toInt() }.toIntArray()
  val t = Array<MutableList<Int>>(n+1) { mutableListOf<Int>() }
  repeat(n-1) {
    val (u, v) = readLine()!!.split(" ").map { it.toInt() }
    t[u].add(v)
    t[v].add(u)
  }
  val stack = Stack<Int>()
  stack.push(1)
  var size = 0
  val pop = BooleanArray(n+1)
  val las = IntArray(n+1)
  val pos = IntArray(n+1)
  val par = IntArray(n+1)
  val lis = IntArray(n+1)
  val ans = IntArray(n+1)
  while (stack.isNotEmpty()) {
    val u = stack.pop()
    if (u > 0) {
      pos[u] = lis.lowerBound(a[u-1], 0, size)
      if (pos[u] == size) {
        pop[u] = true
        size++
      }
      las[u] = lis[pos[u]]
      lis[pos[u]] = a[u-1]
      stack.push(-u)
      ans[u] = size
      for (v in t[u]) {
        if (v == par[u]) continue
        par[v] = u
        stack.push(v)
      }
    } else {
      val v = -u
      if (pop[v]) size-- else lis[pos[v]] = las[v]
    }
  }
  ans.drop(1).forEach { println(it) }
}
fun IntArray.lowerBound(element: Int, fromIndex: Int, toIndex: Int): Int {
  val index = this.binarySearch(element, fromIndex, toIndex)
  return if (index < 0) -index-1 else index
}