Language: C++

#include <iostream>

#include <deque>
#include <queue>
#include <map>

using namespace std;
#define INF 1500000000

 int N,A[200001];

 int prev[200001]={0}; 
 int depth[200001];

int minweight(int vertex,int length);

map<int,int> mem_dp[200001];

int minweight(int vertex,int length){
 if(length<=0)
   return 0;
 if(vertex == 1){
	if(length<=1)
      return A[1];
	else
      return INF;
 }
 if(mem_dp[vertex].find(length)!=mem_dp[vertex].end())
   return mem_dp[vertex][length];
 
  mem_dp[vertex][length] = min(minweight(prev[vertex],length),minweight(prev[vertex],length-1)<A[vertex]?A[vertex]:INF); 
  return mem_dp[vertex][length];
}

int main(){
 deque<int> nbd[200001];
 int score[200001];
 cin >> N;
 
  for(int i=1; i<=N; i++){
  	cin >> A[i];
  }
  for(int i=1; i<=N-1; i++){
    int u,v;
    cin >> u >> v;
    nbd[u].push_back(v);
    nbd[v].push_back(u);
  }
  
  queue<int> q;
  q.push(1);
  depth[1] = 1;
  prev[1] = -1;
  score[1] = 1;
  while(q.empty()==false){
    for(auto x:nbd[q.front()]){
     if(prev[x]==0){
      prev[x] = q.front(); 
      depth[x] = depth[prev[v]]+1;
      int min=1,max=depth[x];
      while(min!=max){
       int t=(min+max+1)/2;
       if(minweight(x,t))==INF)
        max=t-1; 
       else
        min = t;
      }
      score[x] = min;
      q.push(x);
     }
    }
    q.pop();
  }
  
  for(int k =1; k<=N; k++){
   cout << score[k] << endl; 
  }
  return 0;
}

Compiler output:
a.cc: In function 'int minweight(int, int)':
a.cc:31:42: error: reference to 'prev' is ambiguous
   31 |   mem_dp[vertex][length] = min(minweight(prev[vertex],length),minweight(prev[vertex],length-1)<A[vertex]?A[vertex]:INF);
      |                                          ^~~~
In file included from /usr/include/c++/14/string:47,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:12:6: note:                 'int prev [200001]'
   12 |  int prev[200001]={0};
      |      ^~~~
a.cc:31:73: error: reference to 'prev' is ambiguous
   31 |   mem_dp[vertex][length] = min(minweight(prev[vertex],length),minweight(prev[vertex],length-1)<A[vertex]?A[vertex]:INF);
      |                                                                         ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:12:6: note:                 'int prev [200001]'
   12 |  int prev[200001]={0};
      |      ^~~~
a.cc: In function 'int main()':
a.cc:53:3: error: reference to 'prev' is ambiguous
   53 |   prev[1] = -1;
      |   ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:12:6: note:                 'int prev [200001]'
   12 |  int prev[200001]={0};
      |      ^~~~
a.cc:57:9: error: reference to 'prev' is ambiguous
   57 |      if(prev[x]==0){
      |         ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:12:6: note:                 'int prev [200001]'
   12 |  int prev[200001]={0};
      |      ^~~~
a.cc:58:7: error: reference to 'prev' is ambiguous
   58 |       prev[x] = q.front();
      |       ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:12:6: note:                 'int prev [200001]'
   12 |  int prev[200001]={0};
      |      ^~~~
a.cc:59:24: error: reference to 'prev' is ambiguous
   59 |       depth[x] = depth[prev[v]]+1;
      |                        ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:12:6: note:                 'int prev [200001]'
   12 |  int prev[200001]={0};
      |      ^~~~
a.cc:59:29: error: 'v' was not declared in this scope
   59 |       depth[x] = depth[prev[v]]+1;
      |                             ^
a.cc:63:26: error: expected primary-expression before '==' token
   63 |        if(minweight(x,t))==INF)
      |                          ^~