Language: C++

#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<vector<ll> > vec(200005);
vector<pair<ll,ll> > cc;
ll tree[800005],visit[200005],lis[200005],ar[200005],prev1[200005],n;
void upd(ll st,ll en,ll node,ll idx,ll val)
{
    if(st==en)
    {
        tree[node]=val;
        return;
    }
    ll mid=(st+en)/2;
    if(idx<=mid)
        upd(st,mid,2*node,idx,val);
    else
        upd(mid+1,en,2*node+1,idx,val);
    tree[node]=max(tree[2*node],tree[2*node+1]);
}
ll query(ll st,ll en,ll node,ll l,ll r)
{
    if(r<st || l>en)
        return 0;
    if(l<=st && r>=en)
        return tree[node];
    ll mid=(st+en)/2;
    ll p1=query(st,mid,2*node,l,r);
    ll p2=query(mid+1,en,2*node+1,l,r);
    return max(p1,p2);
}
void dfs(ll i)
{
    if(i!=1 && vec[i].size()==1)
        return;
    prev1[i]=query(1,n,1,ar[i],ar[i]);
    upd(1,n,1,ar[i],lis[i]);
    for(auto it=vec[i].begin();it!=vec[i].end();it++)
    {
        if(visit[*it]==0)
        {
            visit[*it]=1;
            lis[*it]=query(1,n,1,1,(ar[*it])-1)+1;
            dfs(*it);
        }
    }
    upd(1,n,1,ar[i],prev1[i]);
}
int main()
{
    ll i,x,y;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>ar[i];
        cc.push_back({ar[i],i});
    }
    sort(cc.begin(),cc.end());
    ll j=1;
    for(i=0;i<cc.size();i++)
    {
        if(i!=0 && cc[i].first==cc[i-1].first)
        {
            j--;
        }
        ar[cc[i].second]=j;
        j++;
    }
    for(i=1;i<n;i++)
    {
        cin>>x>>y;
        vec[x].push_back(y);
        vec[y].push_back(x);
    }
    lis[1]=1;
    visit[1]=1;
    dfs(1);
    for(i=1;i<=n;i++)
    {
        cout<<lis[i]<<"\n";
    }
}


Compiler output:
a.cc: In function 'void dfs(long long int)':
a.cc:40:12: error: reference to 'visit' is ambiguous
   40 |         if(visit[*it]==0)
      |            ^~~~~
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:6:17: note:                 'long long int visit [200005]'
    6 | ll tree[800005],visit[200005],lis[200005],ar[200005],prev1[200005],n;
      |                 ^~~~~
a.cc:42:13: error: reference to 'visit' is ambiguous
   42 |             visit[*it]=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:6:17: note:                 'long long int visit [200005]'
    6 | ll tree[800005],visit[200005],lis[200005],ar[200005],prev1[200005],n;
      |                 ^~~~~
a.cc: In function 'int main()':
a.cc:76:5: error: reference to 'visit' is ambiguous
   76 |     visit[1]=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:6:17: note:                 'long long int visit [200005]'
    6 | ll tree[800005],visit[200005],lis[200005],ar[200005],prev1[200005],n;
      |                 ^~~~~