#include <bits/stdc++.h>

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));
}


template <typename T>
class RollbackableVector{
  std::vector<T> data;
  std::vector<std::vector<T>> stock;
  std::vector<int> history;

public:
  void push_back(const T &value){
    data.push_back(value);
    stock.push_back({value});
    history.push_back(-1);
  }

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

  void roll_back(){
    const int i = history.back(); history.pop_back();

    if(i == -1){
      data.pop_back();
      stock.pop_back();
    }else{
      stock[i].pop_back();
      data[i] = stock[i].back();
    }
  }

  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();}
};




int main(){
  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.assign(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: 37556