#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

// https://ei1333.github.io/luzhiled/snippets/structure/segment-tree.html
template< typename Monoid >
struct PersistentSegmentTree {
  using F = function< Monoid(Monoid, Monoid) >;
 
  struct Node {
    Monoid data;
    Node *l, *r;
 
    Node(const Monoid &data) : data(data), l(nullptr), r(nullptr) {}
  };
 
 
  int sz;
  const F f;
  const Monoid M1;
 
  PersistentSegmentTree(const F f, const Monoid &M1) : f(f), M1(M1) {}
 
  Node *build(vector< Monoid > &v) {
    sz = (int) v.size();
    return build(0, (int) v.size(), v);
  }
 
  Node *merge(Node *l, Node *r) {
    auto t = new Node(f(l->data, r->data));
    t->l = l;
    t->r = r;
    return t;
  }
 
  Node *build(int l, int r, vector< Monoid > &v) {
    if(l + 1 >= r) return new Node(v[l]);
    return merge(build(l, (l + r) >> 1, v), build((l + r) >> 1, r, v));
  }
 
  Node *update(int a, const Monoid &x, Node *k, int l, int r) {
    if(r <= a || a + 1 <= l) {
      return k;
    } else if(a <= l && r <= a + 1) {
      return new Node(x);
    } else {
      return merge(update(a, x, k->l, l, (l + r) >> 1), update(a, x, k->r, (l + r) >> 1, r));
    }
  }
 
  Node *update(Node *t, int k, const Monoid &x) {
    return update(k, x, t, 0, sz);
  }
 
  Monoid query(int a, int b, Node *k, int l, int r) {
    if(r <= a || b <= l) {
      return M1;
    } else if(a <= l && r <= b) {
      return k->data;
    } else {
      return f(query(a, b, k->l, l, (l + r) >> 1),
               query(a, b, k->r, (l + r) >> 1, r));
    }
  }
 
  Monoid query(Node *t, int a, int b) {
    return query(a, b, t, 0, sz);
  }
};

template <class T>
struct Compressor {
  vector<T> xs;
  void put(const T& x) {
    xs.push_back(x);
  }
  void compress() {
    sort(xs.begin(), xs.end());
    xs.erase(unique(xs.begin(), xs.end()), xs.end());
  }
  int get(const T& x) const {
    return distance(xs.begin(), lower_bound(xs.begin(), xs.end(), x));
  }
  int size() const {
    return xs.size();
  }
};

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  while (~scanf("%d", &N)) {
    vector<int> A(N);
    for (auto& x : A) scanf("%d", &x);
    Compressor<int> zip;
    for (auto x : A) zip.put(x);
    zip.compress();
    for (auto& x : A) x = zip.get(x);
    int sz = zip.size();
    vec<int, 2> G(N);
    for (int i = 0; i < N - 1; i++) {
      int a, b;
      scanf("%d %d", &a, &b);
      --a;
      --b;
      G[a].push_back(b);
      G[b].push_back(a);
    }
    PersistentSegmentTree<int> seg([&](int a, int b) { return max(a, b); }, 0);
    vector<int> init(sz, 0);
    auto t = seg.build(init);
    vector<int> res(N);
    auto dfs = [&](auto& dfs, auto t, int v, int p = -1) -> void {
      int best = seg.query(t, 0, A[v]) + 1;
      int curr = seg.query(t, A[v], A[v] + 1);
      auto nt = seg.update(t, A[v], max(best, curr));
      res[v] = seg.query(nt, 0, sz);
      for (int u : G[v]) {
        if (u != p) {
          dfs(dfs, nt, u, v);
        }
      }
    };
    dfs(dfs, t, 0);
    for (int x : res) printf("%d\n", x);
  }
  return 0;
}


Measured memory_bytes: 231116