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

namespace AtTest.ForYellow
{
    class ABC165_F
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int[] array = ReadInts();
            List<int>[] graph = new List<int>[n];
            for(int i = 0; i < n; i++)
            {
                graph[i] = new List<int>();
            }
            for(int i = 0; i < n - 1; i++)
            {
                int[] uv = ReadInts();
                int u = uv[0] - 1;
                int v = uv[1] - 1;
                graph[u].Add(v);
                graph[v].Add(u);
            }

            int[] res = new int[n];
            DFS(graph, array, 0, -1, new List<int>(), res);
            for(int i = 0; i < n; i++)
            {
                WriteLine(res[i]);
            }
        }

        static void DFS(List<int>[] graph,int[] array, int now,int parent,List<int> list,int[] cnts)
        {
            int val = array[now];
            int pos;
            int prev;
            if (list.Count == 0 || list[list.Count - 1] < val)
            {
                pos = -1;
                prev = -1;
                list.Add(val);
            }
            else
            {
                if (val <= list[0])
                {
                    pos = 0;
                    prev = list[0];
                    list[0] = val;
                }
                else
                {
                    int bottom = 0;
                    int top = list.Count - 1;
                    while (bottom + 1 < top)
                    {
                        int mid = (bottom + top) / 2;
                        if (list[mid] >= val)
                        {
                            top = mid;
                        }
                        else
                        {
                            bottom = mid;
                        }
                    }
                    pos = top;
                    prev = list[pos];
                    list[pos] = val;
                }
            }

            cnts[now] = list.Count;

            if (graph[now].Count == 1 && parent >= 0)
            {
                int res = list.Count;
                if (pos==-1)
                {
                    list.RemoveAt(list.Count - 1);
                }
                else
                {
                    list[pos] = prev;
                }
            }
            else
            {
                for(int i = 0; i < graph[now].Count; i++)
                {
                    int to = graph[now][i];
                    if (to == parent)
                    {
                        continue;
                    }

                    DFS(graph, array, to, now, list,cnts);
                }

                if (pos == -1)
                {
                    list.RemoveAt(list.Count - 1);
                }
                else
                {
                    list[pos] = prev;
                }
            }
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 80072