#include <bits/stdc++.h>
#include <variant>

template <typename Cost = int> class Edge{
public:
  int from,to;
  Cost cost;
  Edge() {}
  Edge(int to, Cost cost): to(to), cost(cost){}
  Edge(int from, int to, Cost cost): from(from), to(to), cost(cost){}

  Edge rev() const {return Edge(to,from,cost);}

  friend std::ostream& operator<<(std::ostream &os, const Edge &e){
    os << "(FROM: " << e.from << "," << "TO: " << e.to << "," << "COST: " << e.cost << ")";
    return os;
  }
};

template <typename T> using Graph = std::vector<std::vector<Edge<T>>>;
template <typename T> using Tree = std::vector<std::vector<Edge<T>>>;

template <typename C, typename T> void add_edge(C &g, int from, int to, T w){
  g[from].emplace_back(from, to, w);
}

template <typename C, typename T> void add_undirected(C &g, int a, int b, T w){
  add_edge(g, a, b, w);
  add_edge(g, b, a, w);
}



template <typename F>
struct FixPoint : F{
  explicit constexpr FixPoint(F &&f) noexcept : F(std::forward<F>(f)){}

  template <typename... Args>
  constexpr decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, std::forward<Args>(args)...);
  }
};

template <typename F>
static inline constexpr decltype(auto) make_fix_point(F &&f){
  return FixPoint<F>(std::forward<F>(f));
}





/**
 * @title Rollbackable vector
 * @docs rollbackable_vector.md
 */
template <typename T>
class RollbackableVector {
  using value_type = T;

  std::vector<T> data;


  using Update = std::pair<T, int>;
  struct PushBack {};
  using PopBack = T;

  std::vector<std::variant<Update, PushBack, PopBack>> history;

public:
  RollbackableVector(){}
  RollbackableVector(size_t n): data(n){}
  RollbackableVector(std::vector<T> a): data(a){}
  RollbackableVector(std::initializer_list<T> a): data(a.begin(), a.end()){}

  void push_back(const T &value){
    history.push_back(PushBack());
    data.push_back(value);
  }

  void pop_back(){
    history.push_back(PopBack(data.back()));
    data.pop_back();
  }

  void set(int i, const T &value){
    history.push_back(Update(data[i], i));
    data[i] = value;
  }

  void roll_back(){
    if(std::holds_alternative<Update>(history.back())){
      auto [value, i] = std::get<Update>(history.back());
      data[i] = value;
    }else if(std::holds_alternative<PushBack>(history.back())){
      data.pop_back();
    }else if(std::holds_alternative<PopBack>(history.back())){
      auto value = std::get<PopBack>(history.back());
      data.push_back(value);
    }

    history.pop_back();
  }

  bool rollbackable() const {
    return not history.empty();
  }

  const value_type& operator[](int i) const {return data[i];}

  auto cbegin() const {return data.cbegin();}
  auto cend() const {return data.cend();}

  int size() const {return data.size();}
  bool empty() const {return data.empty();}

  const T& back() const {return data.back();}
  const T& front() const {return data.front();}

  friend std::ostream& operator<<(std::ostream &s, const RollbackableVector &a){
    s << "{";
    for(auto it = a.cbegin(); it != a.cend(); ++it){
      if(it != a.cbegin()) s << ", ";
      s << *it;
    }
    s << "}";
    return s;
  }
};







int main(){
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  int N; std::cin >> N;

  std::vector<int> a(N);
  for(int i = 0; i < N; ++i) std::cin >> a[i];

  Tree<int> tree(N);
  for(int i = 0; i < N-1; ++i){
    int u, v; std::cin >> u >> v;
    --u, --v;
    add_undirected(tree, u, v, 1);
  }

  RollbackableVector<int> dp;
  std::vector<int> ans(N);

  auto f =
    make_fix_point(
      [&](auto &&f, int cur, int par) -> void{
        if(dp.empty() or dp.back() < a[cur]){
          dp.push_back(a[cur]);
        }else{
          int i = std::lower_bound(dp.cbegin(), dp.cend(), a[cur]) - dp.cbegin();
          dp.set(i, a[cur]);
        }

        ans[cur] = dp.size();

        for(auto &e : tree[cur]){
          if(e.to == par) continue;
          f(e.to, cur);
        }

        dp.roll_back();
      });

  f(0, -1);

  for(auto x : ans){
    std::cout << x << "\n";
  }

  return 0;
}


Measured memory_bytes: 40784