Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define fi first
#define se second
#define endl '\n'
#define y1 holyshit
#define all(x) x.begin(),x.end()
const int inf=0x3f3f3f3f;

int N,d[200010],visit[200010],t[200010];
vector<int> cycle;
ll K;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin>>N>>K;
	for(int i=1;i<=N;i++) cin>>d[i];
	int now=1,cnt=0;
	while(!visit[now]){
		visit[now]=++cnt;
		t[visit[now]]=now;
		now=d[now];
	}
	now=visit[now]; cycle.push_back(now);
	int x=d[now]; 
	while(now!=x){
		cycle.push_back(x);
		x=d[x];
	}
	if(K<visit[now]) cout<<t[K+1];
	else cout<<cycle[(K-visit[now]+1)%(ll)cycle.size()];
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:22:16: error: reference to 'visit' is ambiguous
   22 |         while(!visit[now]){
      |                ^~~~~
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:17: note:                 'int visit [200010]'
   13 | int N,d[200010],visit[200010],t[200010];
      |                 ^~~~~
a.cc:23:17: error: reference to 'visit' is ambiguous
   23 |                 visit[now]=++cnt;
      |                 ^~~~~
/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:17: note:                 'int visit [200010]'
   13 | int N,d[200010],visit[200010],t[200010];
      |                 ^~~~~
a.cc:24:19: error: reference to 'visit' is ambiguous
   24 |                 t[visit[now]]=now;
      |                   ^~~~~
/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:17: note:                 'int visit [200010]'
   13 | int N,d[200010],visit[200010],t[200010];
      |                 ^~~~~
a.cc:27:13: error: reference to 'visit' is ambiguous
   27 |         now=visit[now]; cycle.push_back(now);
      |             ^~~~~
/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:17: note:                 'int visit [200010]'
   13 | int N,d[200010],visit[200010],t[200010];
      |                 ^~~~~
a.cc:33:14: error: reference to 'visit' is ambiguous
   33 |         if(K<visit[now]) cout<<t[K+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:17: note:                 'int visit [200010]'
   13 | int N,d[200010],visit[200010],t[200010];
      |                 ^~~~~
a.cc:34:29: error: reference to 'visit' is ambiguous
   34 |         else cout<<cycle[(K-visit[now]+1)%(ll)cycle.size()];
      |                             ^~~~~
/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:17: note:                 'int visit [200010]'
   13 | int N,d[200010],visit[200010],t[200010];
      |                 ^~~~~