using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Out.Flush();
            Read();
        }

        static void Solve()
        {
            var N = Sarray()[0];
            vAi = Sarray();

            graph = Enumerable.Repeat(0, (int)N).Select(_ => new List<long>()).ToArray();
            for (var i = 0; i < N - 1; ++i)
            {
                var (u, v) = Slice2<long>();
                --u; --v;
                graph[u].Add(v);
                graph[v].Add(u);
            }
            lis = new List<long>() { vAi[0] };
            opes = new (long t, long i, long o)[N];
            nums = new long[N];
            nums[0] = 1;
            dfs(0, -1);
            foreach (var n in nums)
                WriteLine(n);
        }
        static List<long>[] graph;
        static long[] vAi;
        static List<long> lis;
        static (long t, long i, long o)[] opes;
        static long[] nums;
        static void dfs(long root, long parent)
        {
            foreach (var g in graph[root])
            {
                if (g == parent) continue;
                ConstLIS(g);
                nums[g] = lis.Count;
                dfs(g, root);
                DestLIS(g);
            }
        }
        static void ConstLIS(long root)
        {
            var v = vAi[root];
            var idx = ~lis.BinarySearch(v, new lb<long>());
            if (lis.Count <= idx)
            {
                opes[root] = (1, 0, 0);
                lis.Add(v);
            }
            else
            {
                opes[root] = (0, idx, lis[idx]);
                lis[idx] = v;
            }
        }
        static void DestLIS(long root)
        {
            var (t, i, o) = opes[root];
            if (t == 1) { lis.RemoveAt(lis.Count - 1); }
            else { lis[(int)i] = o; }
        }
        public class lb<T> : IComparer<T> where T : IComparable<T>
        {
            public int Compare(T x, T y) => 0 <= x.CompareTo(y) ? 1 : -1;
        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 105936