using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;
using System.Text;

namespace ABC165F
{
    class Program
    {
        static int[] a;
        static List<int>[] edge;
        static int N;
        static void Main(string[] args)
        {
            N = RInt;
            a = RInts;
            edge = new List<int>[N].Select(x => new List<int>()).ToArray();
            for (int i = 0; i < N - 1; i++)
            {
                var u = RInt - 1;
                var v = RInt - 1;
                edge[u].Add(v);
                edge[v].Add(u);
            }

            ans = new int[N].Select(x => -1).ToArray();
            ans[0] = 1;
            dp = new int[N].Select(x => INF).ToArray();
            dp[0] = a[0];

            DFS(0);

            StringBuilder sb = new StringBuilder();
            foreach (var a in ans)
            {
                sb.AppendLine(a.ToString());
            }
            Console.WriteLine(sb);
        }

        static int INF = int.MaxValue;
        static int[] ans;
        static int[] dp;
        public static void DFS(int now)
        {
            foreach (var to in edge[now])
            {
                if (ans[to] != -1) continue;

                int index = LowerBound(dp, a[to]);
                var temp = dp[index];
                dp[index] = a[to];
                ans[to] = LowerBound(dp, INF);

                DFS(to);

                dp[index] = temp;
            }
        }

        /// <summary>
        /// 二分探索 key以上の最低
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="a"></param>
        /// <param name="v"></param>
        /// <returns></returns>
        public static int LowerBound<T>(T[] a, T v)
        {
            return LowerBound(a, v, Comparer<T>.Default);
        }

        public static int LowerBound<T>(T[] a, T v, Comparer<T> cmp)
        {
            var l = 0;
            var r = a.Length - 1;
            while (l <= r)
            {
                var mid = l + (r - l) / 2;
                var res = cmp.Compare(a[mid], v);
                if (res == -1) l = mid + 1;
                else r = mid - 1;
            }
            return l;
        }
    }


}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String RNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int RInt => int.Parse(RNext());
        public static long RLong => long.Parse(RNext());
        public static int[] RInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] RLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
        public static string RString => RNext();
        //以下未テスト
        public static int[] RIntsC(int c) => Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray();
        public static long[] RLongsC(int c) => Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray();
        public static char[][] RMap(int h) => Enumerable.Repeat(0, h).Select(x => Console.ReadLine().ToCharArray()).ToArray();
    }

    static class Debug
    {
        static public void Draw2D(int[,] map, int mode = 1)
        {
#if DEBUG
            int W = map.GetLength(0);
            int H = map.GetLength(1);

            int[,] map2 = new int[W + 1, H + 1];
            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (i == 0 && j == 0) map2[i, j] = 0;
                    else if (i == 0) map2[i, j] = j - 1;
                    else if (j == 0) map2[i, j] = i - 1;
                    else map2[i, j] = map[i - 1, j - 1];
                }
            }

            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (mode == 0) Console.Write(map2[i, j] % 10);
                    if (mode == 1) Console.Write(map2[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
#endif
        }

        public static void Draw1D(int[] array, int mode = 0)
        {
#if DEBUG
            Console.WriteLine(string.Join(" ", array));
#endif
        }
    }
}


Measured memory_bytes: 90376