Language: C++

include <bits/stdc++.h>
#define REPZ(i, z, n) for(decltype(n) i = (z); i < (n); i++)
#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(all(v)))
#define MIN(v) (*min_element(all(v)))
#define INF 1000000000000 //1E+12
#define MOD 1000000007    //合同式の法

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<

typedef long long ll;
typedef unsigned long long ul;
// 1s間で可能なループ回数2E+8回
// llの最大値2147483647~2E+9
// long longの最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<> push_back
// 連想配列map<key,value> insert,
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 setprecision()
// to_string<->stoi
// stoll(longlong)
// stod(double)
// 大文字65-90(-32)
// 小文字97-122(+32)
using namespace std;
void dfs(){ 
  return;
}
int main(){
  // faster
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  ll n,k; cin >> n >>k;
  vector<ll> a=vector<ll>(n);
  vector<ll> time=vector<ll>(n+1,-1);
  vector<ll> mitisuzi;
  REP(i,n) cin >> a[i];
  ll v=0;
  mitisuzi.PB(0);
  do{
    time[v]=SIZE(mitisuzi); 
    mitisuzi.PB(a[v]);
    v=a[v]-1;
  }while(time[v]==-1); 
  ll c=SIZE(mitisuzi)-time[v];
  ll l=time[v];
  //cout << c << l;
  //for(int i:mitisuzi) cout << i << endl;
  if(k<=l) cout << mitisuzi[k] << endl;
  else{
    k=k-l;
    k%=c;
    cout << mitisuzi[l+k]<< endl;
  }
  

  return 0;
}


Compiler output:
a.cc:1:1: error: 'include' does not name a type
    1 | include <bits/stdc++.h>
      | ^~~~~~~
a.cc: In function 'int main()':
a.cc:40:3: error: 'ios' has not been declared
   40 |   ios::sync_with_stdio(false);
      |   ^~~
a.cc:41:8: error: 'cin' is not a member of 'std'
   41 |   std::cin.tie(nullptr);
      |        ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | include <bits/stdc++.h>
a.cc:43:3: error: 'll' was not declared in this scope; did you mean 'ul'?
   43 |   ll n,k; cin >> n >>k;
      |   ^~
      |   ul
a.cc:43:11: error: 'cin' was not declared in this scope
   43 |   ll n,k; cin >> n >>k;
      |           ^~~
a.cc:43:11: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:43:18: error: 'n' was not declared in this scope
   43 |   ll n,k; cin >> n >>k;
      |                  ^
a.cc:43:22: error: 'k' was not declared in this scope
   43 |   ll n,k; cin >> n >>k;
      |                      ^
a.cc:44:3: error: 'vector' was not declared in this scope
   44 |   vector<ll> a=vector<ll>(n);
      |   ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | include <bits/stdc++.h>
a.cc:44:14: error: 'a' was not declared in this scope
   44 |   vector<ll> a=vector<ll>(n);
      |              ^
a.cc:45:14: error: 'time' was not declared in this scope
   45 |   vector<ll> time=vector<ll>(n+1,-1);
      |              ^~~~
a.cc:1:1: note: 'time' is defined in header '<ctime>'; this is probably fixable by adding '#include <ctime>'
  +++ |+#include <ctime>
    1 | include <bits/stdc++.h>
a.cc:46:14: error: 'mitisuzi' was not declared in this scope
   46 |   vector<ll> mitisuzi;
      |              ^~~~~~~~
a.cc:48:5: error: expected ';' before 'v'
   48 |   ll v=0;
      |     ^~
      |     ;
a.cc:51:10: error: 'v' was not declared in this scope
   51 |     time[v]=SIZE(mitisuzi);
      |          ^
a.cc:54:15: error: 'v' was not declared in this scope
   54 |   }while(time[v]==-1);
      |               ^
a.cc:55:5: error: expected ';' before 'c'
   55 |   ll c=SIZE(mitisuzi)-time[v];
      |     ^~
      |     ;
a.cc:56:5: error: expected ';' before 'l'
   56 |   ll l=time[v];
      |     ^~
      |     ;
a.cc:59:9: error: 'l' was not declared in this scope; did you mean 'ul'?
   59 |   if(k<=l) cout << mitisuzi[k] << endl;
      |         ^
      |         ul
a.cc:59:12: error: 'cout' was not declared in this scope
   59 |   if(k<=l) cout << mitisuzi[k] << endl;
      |            ^~~~
a.cc:59:12: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:59:35: error: 'endl' was not declared in this scope
   59 |   if(k<=l) cout << mitisuzi[k] << endl;
      |                                   ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 | include <bits/stdc++.h>
a.cc:62:8: error: 'c' was not declared in this scope
   62 |     k%=c;
      |        ^
a.cc:63:5: error: 'cout' was not declared in this scope
   63 |     cout << mitisuzi[l+k]<< endl;
      |     ^~~~
a.cc:63:5: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:63:29: error: 'endl' was not declared in this scope
   63 |     cout << mitisuzi[l+k]<< endl;
      |                             ^~~~
a.cc:63:29: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'