#pragma region kyomukyomupurin

/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-05-22 12:36:08
 **/

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using int64 = long long;

template <class T>
using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

#pragma endregion kyomukyomupurin

using graph = std::vector<std::vector<int>>;
using pii = std::pair<int, int>;

template<class T>
void Unique(std::vector<T>& vec) {
  std::sort(vec.begin(), vec.end());
  vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
  return ;
}

template <class Monoid, class Function>
class SegmentTree {
 public:
  SegmentTree(const std::vector<Monoid>& data, Monoid identity_element,
              Function function)
      : identity_element_(identity_element), data_(data), function_(function) {
    build();
  }

  void update(int pos, Monoid new_value) {
    assert(0 <= pos && pos < n_);
    pos += n_;
    node_[pos] = new_value;
    while (pos > 0) {
      pos >>= 1;
      node_[pos] = function_(node_[2 * pos], node_[2 * pos + 1]);
    }
  }

  // return function_[l, r)
  Monoid query(int l, int r) {
    //assert(0 <= l && l < n_ && 0 <= r - 1 && r - 1 < n_);
    Monoid vl = identity_element_, vr = identity_element_;
    for (l += n_, r += n_; l < r; l >>= 1, r >>= 1) {
      if (l & 1) vl = function_(vl, node_[l++]);
      if (r & 1) vr = function_(node_[--r], vr);
    }
    return function_(vl, vr);
  }

  Monoid operator[](int pos) const {
    assert(0 <= pos && pos < n_);
    return node_[n_ + pos];
  }

 private:
  int n_;
  Monoid identity_element_;
  std::vector<Monoid> data_;
  std::vector<Monoid> node_;
  Function function_;

  void build() {
    int SIZE = data_.size();
    n_ = 1;
    while (n_ < SIZE) {
      n_ <<= 1;
    }
    node_.assign(2 * n_, identity_element_);
    for (int i = 0; i < SIZE; ++i) {
      node_[i + n_] = data_[i];
    }
    for (int i = n_ - 1; i > 0; --i) {
      node_[i] = function_(node_[2 * i], node_[2 * i + 1]);
    }
  }
};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n; cin >> n;
  vector<int> a(n); cin >> a;
  vector b = a;
  sort(all(b));
  b.erase(unique(all(b)), b.end());
  for (int& e : a) e = distance(b.begin(), lower_bound(all(b), e));

  graph g(n);
  for (int i = 0; i < n - 1; ++i) {
    int u, v; cin >> u >> v; --u; --v;
    g[u].emplace_back(v);
    g[v].emplace_back(u);
  }

  auto f = [](int x, int y){ return max(x, y); };

  // seg[i] : the longest length of LIS which ends with i
  SegmentTree<int, decltype(f)> seg(vector<int>(202020, 0), 0, f);
  
  vector<int> ans(n, -1);

  debug(a);

  auto dfs = [&](auto&& rec, int cur, int pre = -1) -> void {
    int tmp = seg[a[cur]];
    seg.update(a[cur], seg.query(0, a[cur]) + 1);
    ans[cur] = seg.query(0, 202020);
    for (int nxt : g[cur]) {
      if (nxt == pre) continue;
      rec(rec, nxt, cur);
    }
    seg.update(a[cur], tmp);
  };

  dfs(dfs, 0);

  assert(none_of(all(ans), [](int e){ return e == -1; }));

  for (int e : ans) cout << e << '\n';

  return 0;
}

Measured memory_bytes: 33512