Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,P>
using namespace std;
vector<vector<int> > ki;
vector<int> rw;
int memo[300000];
vector<int> visit;

void solve(int now,int p,int tmp){
    visit[now]=1;
    if(rw[now]>rw[p]) tmp++;
    else tmp=1;
    memo[now]=max(memo[p],tmp);
    rep(i,ki[now].size()){
        if(visit[ki[now][i]]) continue;
        solve(ki[now][i],now,tmp);
    }
    return;
}

int main(){
    int n; cin >> n;
    rw.resize(n+1);
    ki.resize(n);
    visit.resize(n);
    rep(i,n){
        cin >> rw[i];
        visit[i]=0;
    }
    rw[n]=-1;
    rep(i,n-1){
        int u,v; cin >> u >> v;
        u--; v--;
        ki[u].push_back(v);
        ki[v].push_back(u);
    }
    solve(0,n,0);
    rep(i,n) cout << memo[i] << endl;
return 0;
}







Compiler output:
a.cc: In function 'void solve(int, int, int)':
a.cc:16:5: error: reference to 'visit' is ambiguous
   16 |     visit[now]=1;
      |     ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:1:
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:13:13: note:                 'std::vector<int> visit'
   13 | vector<int> visit;
      |             ^~~~~
a.cc:21:12: error: reference to 'visit' is ambiguous
   21 |         if(visit[ki[now][i]]) continue;
      |            ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:13:13: note:                 'std::vector<int> visit'
   13 | vector<int> visit;
      |             ^~~~~
a.cc: In function 'int main()':
a.cc:31:5: error: reference to 'visit' is ambiguous
   31 |     visit.resize(n);
      |     ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:13:13: note:                 'std::vector<int> visit'
   13 | vector<int> visit;
      |             ^~~~~
a.cc:34:9: error: reference to 'visit' is ambiguous
   34 |         visit[i]=0;
      |         ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:13:13: note:                 'std::vector<int> visit'
   13 | vector<int> visit;
      |             ^~~~~