Language: C++

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#include <time.h>
#include <iostream>
#include <vector>
#include <map>

using namespace std;
int main()
{
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n + 1);
  vector<bool> seen(n + 1, false);
  seen[1] = true;
  for (ll i = 1; i < n + 1; i++)
  {
    cin >> a[i];
  }
  if (k < n)
  {
    int now = 1;
    for (ll i = 0; i < k; i++)
    {
      now = a[now];
    }
    cout << now << endl;
    return 0;
  }
  ll now = 1;
  k--;
  for (; k != 0; k--)
  {
    now = a[now];
    if (seen[now])
      break;
    seen[now] = true;
  }
  if (k == 0)
  {
    cout << now << endl;
    return 0;
  }
  vector<bool> seen_2(n + 1, false);
  seen_2[now] = true;
  ll repeat = 1;
  for (ll i = 0;; i++)
  {
    now = a[now];
    if (seen_2[now])
      break;
    seen_2[now] = true;
    repeat++;
  }
  // cout << k << endl;
  // cout << repeat << endl;
  k %= repeat;
  // cout << k << endl;
  for (ll i = 0; i < k; i++)
  {
    now = a[now];
  }
  cout << now << endl;

  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:13:3: error: 'll' was not declared in this scope
   13 |   ll n, k;
      |   ^~
a.cc:14:10: error: 'n' was not declared in this scope; did you mean 'yn'?
   14 |   cin >> n >> k;
      |          ^
      |          yn
a.cc:14:15: error: 'k' was not declared in this scope
   14 |   cin >> n >> k;
      |               ^
a.cc:15:12: error: template argument 2 is invalid
   15 |   vector<ll> a(n + 1);
      |            ^
a.cc:18:10: error: expected ';' before 'i'
   18 |   for (ll i = 1; i < n + 1; i++)
      |          ^~
      |          ;
a.cc:18:18: error: 'i' was not declared in this scope
   18 |   for (ll i = 1; i < n + 1; i++)
      |                  ^
a.cc:25:12: error: expected ';' before 'i'
   25 |     for (ll i = 0; i < k; i++)
      |            ^~
      |            ;
a.cc:25:20: error: 'i' was not declared in this scope
   25 |     for (ll i = 0; i < k; i++)
      |                    ^
a.cc:27:14: error: invalid types 'int[int]' for array subscript
   27 |       now = a[now];
      |              ^
a.cc:32:5: error: expected ';' before 'now'
   32 |   ll now = 1;
      |     ^~~~
      |     ;
a.cc:36:5: error: 'now' was not declared in this scope; did you mean 'pow'?
   36 |     now = a[now];
      |     ^~~
      |     pow
a.cc:43:13: error: 'now' was not declared in this scope; did you mean 'pow'?
   43 |     cout << now << endl;
      |             ^~~
      |             pow
a.cc:47:10: error: 'now' was not declared in this scope; did you mean 'pow'?
   47 |   seen_2[now] = true;
      |          ^~~
      |          pow
a.cc:48:5: error: expected ';' before 'repeat'
   48 |   ll repeat = 1;
      |     ^~~~~~~
      |     ;
a.cc:49:10: error: expected ';' before 'i'
   49 |   for (ll i = 0;; i++)
      |          ^~
      |          ;
a.cc:49:19: error: 'i' was not declared in this scope
   49 |   for (ll i = 0;; i++)
      |                   ^
a.cc:55:5: error: 'repeat' was not declared in this scope
   55 |     repeat++;
      |     ^~~~~~
a.cc:59:8: error: 'repeat' was not declared in this scope
   59 |   k %= repeat;
      |        ^~~~~~
a.cc:61:10: error: expected ';' before 'i'
   61 |   for (ll i = 0; i < k; i++)
      |          ^~
      |          ;
a.cc:61:18: error: 'i' was not declared in this scope
   61 |   for (ll i = 0; i < k; i++)
      |                  ^