Language: C++

#include<bits/stdc++.h>
using namespace std;
const int ms = 2e5+9;
vector<int> jump_pos;
vector<int> g[ms], path;
int n, first_repeated_node, visit[ms], solution = 0;
long long int k, cycle_size;

int dfs(int node, int t22 =1){
  path.push_back(node);
  visit[node] = t22++;

  for(auto &v : g[node]){
    if(visit[v]){
      cycle_size = t22 - visit[v];
      return v;
    } else {
      int v2 = dfs(v, t22);
      if(v2 != -1){
        return v2;
        }
    }
  }

  return -1;
}


int solve(){
  int t = 0;
  for(t = 0; t < path.size() and k; t++, k--){
    if(path[t] == first_repeated_node){
      break;
    }
  }
  if(k == 0)
    return path[t];

  k%=cycle_size;


  return path[k + visit[first_repeated_node] - 1];
}

int main(){
  cin >> n >> k;
  jump_pos.resize(n+1);

  for(int i = 1; i <= n; i++){
    cin >> jump_pos[i];
    g[i].push_back(jump_pos[i]);
  }

    first_repeated_node = dfs(1);

  cout<<solve()<<endl;

}

Compiler output:
a.cc: In function 'int dfs(int, int)':
a.cc:11:3: error: reference to 'visit' is ambiguous
   11 |   visit[node] = t22++;
      |   ^~~~~
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:29: note:                 'int visit [200009]'
    6 | int n, first_repeated_node, visit[ms], solution = 0;
      |                             ^~~~~
a.cc:14:8: error: reference to 'visit' is ambiguous
   14 |     if(visit[v]){
      |        ^~~~~
/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:29: note:                 'int visit [200009]'
    6 | int n, first_repeated_node, visit[ms], solution = 0;
      |                             ^~~~~
a.cc:15:26: error: reference to 'visit' is ambiguous
   15 |       cycle_size = t22 - visit[v];
      |                          ^~~~~
/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:29: note:                 'int visit [200009]'
    6 | int n, first_repeated_node, visit[ms], solution = 0;
      |                             ^~~~~
a.cc: In function 'int solve()':
a.cc:42:19: error: reference to 'visit' is ambiguous
   42 |   return path[k + visit[first_repeated_node] - 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:29: note:                 'int visit [200009]'
    6 | int n, first_repeated_node, visit[ms], solution = 0;
      |                             ^~~~~