Language: C++

#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
V<int> g;
V<bool> visit;
bool cc;
V<int> cir;
int siz;
int st;
void dfs(int cur,int last){
    if(last==cur)return;
   if(!visit[g[cur]]){
        visit[g[cur]]=true;
        dfs(g[cur],cur);
    }else{
         int next=(cc?cur:last);
         if(cc)st=cur;
         cc=false;
         cir.emplace_back(cur);
         dfs(g[cur],next);
    }
    return;
}
int main(){
 ll  n,k;
 cin>>n>>k;
 V<ll> d(n);
 g.resize(n);
 visit.assign(n,false);
 cc=true;
 for(int i=0;i<n;i++){
   cin>>d[i];
   g[i]=d[i]-1;
  }
  visit[0]=true;
  dfs(0,-1);
  int now=0;
  int cnt=0;
    if(k<200005){
     ll x=ll(k);
     now=0;
    for(int i=0;i<x;i++){
      now=g[now];
      }
      cout<<now+1<<"\n";
      return 0;
   }
  for(int i=0;i<n;i++){
    if(now==st)break;
     now=g[now];cnt++;
   }
   k-=cnt;
   int m=cir.size();
   cout<<cir[k%m]+1<<"\n";
}


Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:25:8: error: reference to 'visit' is ambiguous
   25 |    if(!visit[g[cur]]){
      |        ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:2:
/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:18:9: note:                 'V<bool> visit'
   18 | V<bool> visit;
      |         ^~~~~
a.cc:26:9: error: reference to 'visit' is ambiguous
   26 |         visit[g[cur]]=true;
      |         ^~~~~
/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:18:9: note:                 'V<bool> visit'
   18 | V<bool> visit;
      |         ^~~~~
a.cc: In function 'int main()':
a.cc:42:2: error: reference to 'visit' is ambiguous
   42 |  visit.assign(n,false);
      |  ^~~~~
/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:18:9: note:                 'V<bool> visit'
   18 | V<bool> visit;
      |         ^~~~~
a.cc:48:3: error: reference to 'visit' is ambiguous
   48 |   visit[0]=true;
      |   ^~~~~
/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:18:9: note:                 'V<bool> visit'
   18 | V<bool> visit;
      |         ^~~~~