Language: C++

    #include<bits/stdc++.h>
    #define int ll
	#define pb push_back
    #define ll long long
    using namespace std;
    vector <int> v(200005);
    int visit[200005];
    int power(int x, unsigned int y, unsigned int m) 
	{ 
    	if (y == 0) 
        	return 1; 
    	int p = power(x, y/2, m) % m; 
    	p = (p * p) % m; 
  
 	   return (y%2 == 0)? p : (x * p) % m; 
	} 
	int modInverse(int a, int m) 
	{   
    	return power(a, m-2, m);
	}
    signed main()
    {
    	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    	ll t=1;
    	// cout<<1;
    	// cin >> t;
    	/*SAARE INPUTS LENA*/
    	/*VARIABLES KI RANGE DEKHLENA*/
    	while(t-->0)
    	{
    		ll n=0,k=0;
    		cin>>n>>k;
    		ll a=0;
    		for (int i = 0; i < n; ++i)
    		{
    			cin>>a;
    			// cout<<1;
    			v[i+1]=(a);
    		}
    		for (int i = 0; i <=n; ++i)
    		{
    			visit[i]=false;
    		}
    		// for (int i = 1; i <=n; ++i)
    		// {
    		// 	cout<<v[i]<<" ";
    		// }
    		// cout<<endl;
    		visit[1]=true;
    		queue<int> q;
    		q.push(1);
    		int cnt=0,loop=0;
    		int c[n+1];
    		vector <int> ans;
    		while(!q.empty())
    		{
    			int x=q.front();
    			q.pop();
    			// cout<<x<<endl;
    			cnt++;
    			c[x]=cnt;
    			ans.pb(x);
    			if(visit[v[x]]==true)
    			{
    				loop=cnt-c[v[x]]+1;
    			}
    			else
    			{	q.push(v[x]); visit[v[x]]=true;}
    		}
    		int f=(k-(cnt-loop))%loop+(cnt-loop)+1;
    		// for (int i = 0; i < ans.size(); ++i)
    		// {
    		// 	cout<<ans[i]<<" ";
    		// }
    		// cout<<endl;
    		// cout<<cnt<<" "<<loop<<" "<<f<<endl;
    		cout<<ans[f-1];
    	}
    	return 0;
    }

Compiler output:
a.cc: In function 'int main()':
a.cc:42:25: error: reference to 'visit' is ambiguous
   42 |                         visit[i]=false;
      |                         ^~~~~
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:7:9: note:                 'long long int visit [200005]'
    7 |     int visit[200005];
      |         ^~~~~
a.cc:49:17: error: reference to 'visit' is ambiguous
   49 |                 visit[1]=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:7:9: note:                 'long long int visit [200005]'
    7 |     int visit[200005];
      |         ^~~~~
a.cc:63:28: error: reference to 'visit' is ambiguous
   63 |                         if(visit[v[x]]==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:7:9: note:                 'long long int visit [200005]'
    7 |     int visit[200005];
      |         ^~~~~
a.cc:68:47: error: reference to 'visit' is ambiguous
   68 |                         {       q.push(v[x]); visit[v[x]]=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:7:9: note:                 'long long int visit [200005]'
    7 |     int visit[200005];
      |         ^~~~~