Language: C++

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }


//方針
//・最長増加部分列(LIS) の長さを点1から各点への最小パスについてそれぞれ求める
//LISを1からつくるにはO(NlogN)、 長さの調査にはO(logN) 必要
// <- 毎回LISを生成するとO( (NlogN)^2 ) かかる
// -> 深さ優先探索(DFS) & 探索ごとにLISを更新 
//    (1探索当たりO(logN)*N点 -> O(NlogN) )
// <- 素朴に更新を繰り返すと復路で壊れる
// -> 更新前の状態を復元できるよう、stackで情報保持
//全点通過で探索終了

#define INF 1e15
#define MAX 300000
ll N;
ll a[MAX];
ll dp[MAX];
ll visit[MAX];
ll ans[MAX];
vector<ll> cnct[MAX];
stack< pair<ll,ll> > stk;

void dfs(int k){
    visit[k] = true;
    ll idx = distance(dp,lower_bound(dp,dp+N+1,a[k]));
    stk.push( make_pair(idx, dp[idx] ) );
    dp[idx] = a[k];
    ans[k] = distance(dp,lower_bound(dp,dp+N+1,INF));
    for(ll nxt: cnct[k]){
        if(visit[nxt]==0LL){
            dfs(nxt);
        }
    }
    idx = stk.top().first;
    dp[idx] = stk.top().second;
    stk.pop();
}

int main(){
  cin>>N;
  a[0] = 0;
  for(ll i=1;i<=N;++i){ cin >> a[i]; }
  FILL(dp,N+1,INF);
  FILL(visit,N+1,0LL);
  REP(i,N){
    ll u,v; cin>>u>>v;
    cnct[u].push_back(v);
    cnct[v].push_back(u);
  }
  dfs(1);
  for(int i=1;i<=N;++i){
    cout << ans[i] << "\n";
  }
}

Compiler output:
a.cc: In function 'void dfs(int)':
a.cc:52:5: error: reference to 'visit' is ambiguous
   52 |     visit[k] = true;
      |     ^~~~~
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:46:4: note:                 'll visit [300000]'
   46 | ll visit[MAX];
      |    ^~~~~
a.cc:58:12: error: reference to 'visit' is ambiguous
   58 |         if(visit[nxt]==0LL){
      |            ^~~~~
/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:46:4: note:                 'll visit [300000]'
   46 | ll visit[MAX];
      |    ^~~~~
a.cc: In function 'int main()':
a.cc:72:8: error: reference to 'visit' is ambiguous
   72 |   FILL(visit,N+1,0LL);
      |        ^~~~~
a.cc:9:35: note: in definition of macro 'FILL'
    9 | #define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
      |                                   ^
/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:46:4: note:                 'll visit [300000]'
   46 | ll visit[MAX];
      |    ^~~~~