Language: C++

#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<型名>()で降順
#include <map>

using namespace std;
using ll = long long int;

int main(){
    ll N,K;cin>>N>>K;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        int b;cin>>b;
        b--;
        A[i] = b;
    }
    vector<bool> a(N,false);
    int to = 0;
    int start;
    while(1){
        if(a[to]==true){
            start = to;
            break;
        }else{
            a[to] = true;
            to = A[to];
        }
    }
    for(int i=0;i<N;i++){
        a[i] = false;
    }
    to = 0;
    bool b_or_a = false;
    if(start==0) b_or_a = true;
    vector<int> aloop;
    vector<int> bloop;
    while(1){
        if(b_or_a){
            if(a[to]) break;
            aloop.push_back(to);
        }else{
            if(to==start){
                b_or_a = true;
                aloop.push_back(to);
            }else{
                bloop.push_back(to);
            }
        }
        a[to] = true;
        to = A[to];
    }
    if(K<=(ll)bloop.size()){
        cout << bloop[K] + 1 << endl;
    }else{
        K -= bloop.size();
        K %= aloop.size();
        cout << aloop[K] + 1 << endl;
    }
    return 0;
}#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<型名>()で降順
#include <map>

using namespace std;
using ll = long long int;

int main(){
    ll N,K;cin>>N>>K;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        int b;cin>>b;
        b--;
        A[i] = b;
    }
    vector<bool> a(N,false);
    int to = 0;
    int start;
    while(1){
        if(a[to]==true){
            start = to;
            break;
        }else{
            a[to] = true;
            to = A[to];
        }
    }
    for(int i=0;i<N;i++){
        a[i] = false;
    }
    to = 0;
    bool b_or_a = false;
    if(start==0) b_or_a = true;
    vector<int> aloop;
    vector<int> bloop;
    while(1){
        if(b_or_a){
            if(a[to]) break;
            aloop.push_back(to);
        }else{
            if(to==start){
                b_or_a = true;
                aloop.push_back(to);
            }else{
                bloop.push_back(to);
            }
        }
        a[to] = true;
        to = A[to];
    }
    if(K<=(ll)bloop.size()){
        cout << bloop[K] + 1 << endl;
    }else{
        K -= bloop.size();
        K %= aloop.size();
        cout << aloop[K] + 1 << endl;
    }
    return 0;
}

Compiler output:
a.cc:67:2: error: stray '#' in program
   67 | }#include <iostream>//cout<<right で右揃え
      |  ^
a.cc:67:3: error: 'include' does not name a type
   67 | }#include <iostream>//cout<<right で右揃え
      |   ^~~~~~~
a.cc:82:5: error: redefinition of 'int main()'
   82 | int main(){
      |     ^~~~
a.cc:16:5: note: 'int main()' previously defined here
   16 | int main(){
      |     ^~~~