Language: C++

//snukeさんの丸コピ#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n; ll k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  vector<int> s;
  vector<int> ord(n+1,-1);
  int c = 1, l = 0;
  {
    int v = 1;
    while (ord[v] == -1) {
      ord[v] = s.size();
      s.push_back(v);
      v = a[v-1];
    }
    c = s.size() - ord[v];
    l = ord[v];
  }

  if (k < l) cout << s[k] << endl;
  else {
    k -= l;
    k %= c;
    cout << s[l+k] << endl;
  }
  return 0;
}


Compiler output:
a.cc:5:11: error: 'pair' does not name a type
    5 | using P = pair<int,int>;
      |           ^~~~
a.cc: In function 'int main()':
a.cc:9:3: error: 'cin' was not declared in this scope
    9 |   cin >> n >> k;
      |   ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | //snukeさんの丸コピ#include <bits/stdc++.h>
a.cc:10:3: error: 'vector' was not declared in this scope
   10 |   vector<int> a(n);
      |   ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | //snukeさんの丸コピ#include <bits/stdc++.h>
a.cc:10:10: error: expected primary-expression before 'int'
   10 |   vector<int> a(n);
      |          ^~~
a.cc:11:19: error: 'a' was not declared in this scope
   11 |   rep(i,n) cin >> a[i];
      |                   ^
a.cc:13:10: error: expected primary-expression before 'int'
   13 |   vector<int> s;
      |          ^~~
a.cc:14:10: error: expected primary-expression before 'int'
   14 |   vector<int> ord(n+1,-1);
      |          ^~~
a.cc:18:12: error: 'ord' was not declared in this scope
   18 |     while (ord[v] == -1) {
      |            ^~~
a.cc:19:16: error: 's' was not declared in this scope
   19 |       ord[v] = s.size();
      |                ^
a.cc:21:11: error: 'a' was not declared in this scope
   21 |       v = a[v-1];
      |           ^
a.cc:23:9: error: 's' was not declared in this scope
   23 |     c = s.size() - ord[v];
      |         ^
a.cc:23:20: error: 'ord' was not declared in this scope
   23 |     c = s.size() - ord[v];
      |                    ^~~
a.cc:27:14: error: 'cout' was not declared in this scope
   27 |   if (k < l) cout << s[k] << endl;
      |              ^~~~
a.cc:27:14: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:27:22: error: 's' was not declared in this scope
   27 |   if (k < l) cout << s[k] << endl;
      |                      ^
a.cc:27:30: error: 'endl' was not declared in this scope
   27 |   if (k < l) cout << s[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 | //snukeさんの丸コピ#include <bits/stdc++.h>
a.cc:31:5: error: 'cout' was not declared in this scope
   31 |     cout << s[l+k] << endl;
      |     ^~~~
a.cc:31:5: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:31:13: error: 's' was not declared in this scope
   31 |     cout << s[l+k] << endl;
      |             ^
a.cc:31:23: error: 'endl' was not declared in this scope
   31 |     cout << s[l+k] << endl;
      |                       ^~~~
a.cc:31:23: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'