using System;
using System.Linq;
using System.Collections.Generic;

namespace Contest
{
  class Program
  {
    static void Main(string[] args)
    {
      ABC165.F();
    }
    class ABC165
    {
      public static void A()
      {
        var K = Read.Int();
        var A = Read.Int();
        var B = Read.Int();
        for(int i = A; i <= B; ++i)
        {
          if (i % K == 0)
          {
            Console.WriteLine("OK");
            return;
          }
        }
        Console.WriteLine("NG");
      }
      public static void B()
      {
        var X = Read.Long();
        long current = 100;
        int count = 0;
        while (current < X)
        {
          current += current / 100;
          count++;
        }
        Console.WriteLine(count);
      }
      public static void C()
      {
        var N = Read.Int();
        var M = Read.Int();
        var Q = Read.Int();
        var ABCD = Enumerable.Range(0, Q).Select(i => Read.IntN()).ToArray();
        var A = new int[N];
        A[0] = 1;
        Console.WriteLine(C_DFS(A, 1, N, M, ABCD, 0));
      }
      static int C_DFS(int[] A, int depth, int N, int M, int[][] ABCD, int score)
      {
        if (depth == N)
        {
          int sum = 0;
          for (int i = 0; i < ABCD.Length; ++i)
          {
            var abcd = ABCD[i];
            if (A[abcd[1] - 1] - A[abcd[0] - 1] == abcd[2]) { sum += abcd[3]; }
          }
          return sum;
        }
        else
        {
          int res = score;
          for (int i = A[depth - 1]; i <= M; ++i)
          {
            A[depth] = i;
            res = Math.Max(res, C_DFS(A, depth + 1, N, M, ABCD, score));
          }
          return res;
        }
      }
      public static void D()
      {
        var A = Read.Long();
        var B = Read.Long();
        var N = Read.Long();
        var X = Math.Min(B - 1, N);
        Console.WriteLine(A * X / B - X / B * A);
      }
      public static void E()
      {
        var N = Read.Int();
        var M = Read.Int();
        var sb = new System.Text.StringBuilder();
        if (N % 2 == 1)
        {
          for (int i = 0; i < M; ++i)
          {
            sb.AppendLine(String.Format("{0} {1}", i + 1, N - 1 - i));
          }
        }
        else
        {
          for(int i = 0; i < M; ++i)
          {
            sb.AppendLine(String.Format("{0} {1}", i + 1, N - i - ((i >= (N / 2) / 2) ? 1 : 0)));
          }
        }
        Console.Write(sb.ToString());
      }
      public static void F()
      {
        var N = Read.Int();
        var A = Read.IntN();
        var Adj = Read.AdjacencyList(N, N - 1);
        var Dist = Util.CalcDistance_OnTree(Adj, N, 1);
        int INF = 2000000000;
        var dp = Enumerable.Range(0, N + 1).Select(i => INF).ToArray();
        dp[0] = 0;
        var ans = Enumerable.Range(0, N + 1).Select(i => -1).ToArray();
        var stack = new Stack<Tuple<bool, int, int, int>>();
        stack.Push(new Tuple<bool, int, int, int>(true, 1, 0, 0));
        ans[1] = 1;
        while (stack.Count > 0)
        {
          var t = stack.Pop();
          if (!t.Item1)
          {
            dp[t.Item2] = t.Item3;
            continue;
          }
          var v = t.Item2;
          var a = A[v - 1];
          var idx = Util.Lowerbound(dp, a);
          stack.Push(new Tuple<bool, int, int, int>(false, idx, dp[idx], a));
          dp[idx] = a;
          var len = Util.Lowerbound(dp, INF - 1) - 1;
          ans[v] = len;
          foreach(var w in Adj[v])
          {
            if (ans[w] < 0)
            {
              stack.Push(new Tuple<bool, int, int, int>(true, w, 0, 0));
            }
          }
        }
        Console.WriteLine(String.Join(Environment.NewLine, ans.Skip(1)));
      }
    }
    class Util
    {
      public static int[] CalcDistance_OnTree(Dictionary<int, HashSet<int>> adj, int N, int start)
      {
        var dist = Enumerable.Range(0, N + 1).Select(i => -1).ToArray();
        dist[start] = 0;
        Queue<int> queue = new Queue<int>();
        queue.Enqueue(start);
        while (queue.Count > 0)
        {
          var v = queue.Dequeue();
          foreach (var w in adj[v])
          {
            if (dist[w] < 0)
            {
              dist[w] = dist[v] + 1;
              queue.Enqueue(w);
            }
          }
        }
        return dist;
      }
      public static int Lowerbound<T1, T2>(SortedList<T1, T2> list, T1 x) where T1 : IComparable<T1>
      {
        return Lowerbound(list.Keys, x);
      }
      public static int Lowerbound<T>(IList<T> list, T x) where T : IComparable<T>
      {
        int min = 0;
        int max = list.Count;
        while (min < max)
        {
          var mid = (min + max) / 2;
          if (list[mid].CompareTo(x) >= 0)
          {
            max = mid;
          }
          else
          {
            min = mid + 1;
          }
        }
        return max;
      }
    }


    static class Read
{
static Queue<string> queue = new Queue<string>();
static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } }
public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); }
public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); }
public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); }
public static int[] IntN() { return Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray(); }
public static long[] LongN() { return Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray(); }
public static ulong[] ULongN() { return Console.ReadLine().Split(' ').Select(s => Convert.ToUInt64(s)).ToArray(); }
public static string[] StrN() { return Console.ReadLine().Split(' '); }
public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); }
public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); }
public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); }
public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); }
public static long[,] LongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = Read.LongN(); for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; }
public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M, bool isDirectional = false)
{
Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>();
for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); }
for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1]); if (!isDirectional) { dict[ab[1]].Add(ab[0]); } }
return dict;
}
public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M)
{
Dictionary<int, Dictionary<int, long>> dict = new Dictionary<int, Dictionary<int, long>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new Dictionary<int, long>()); }
for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1], ab[2]); dict[ab[1]].Add(ab[0], ab[2]); }
return dict;
}
}
    }
}


Measured memory_bytes: 87040