Language: C++

#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  long long int K;

  cin >> N >> K;
  //cout << K;
  vector <int> A(N),a(N),b(N);


  for(int i=0; i<N; i++){
    cin >> A.at(i);

  }

  for(int i=0; i<N; i++){
    if(i==0){
      a.at(i)=A.at(i);

    }
    else{
      a.at(i)=A.at(a.at(i-1)-1);
    }
    //cout << a.at(i) << " " ;
  }
  bool frag=false;
  b = sort(a.begin(),a.end());
  for(int i=0; i<N-1;i++){
    if(b.at(i)==b.at(i+1)){
      frag = true;
    }
  }

  //cout << endl;

  long long int count=0,cycle=N;
  for(long long int i=0; i<N; i++){
    if(frag==false){
      break;
    for(long long int j=1;i+j<N;j++){
      }
      if(a.at(i)==a.at(i+j)){
        count = i;
        cycle = j;
        //cout << i << " " << j <<endl;
        frag = false;
      }
      if(frag==false){
        break;
      }
    }
  }

  K -= count;
  K %= cycle;
  //cout << K;
  if(count != 0 && K ==0){
    K = cycle;
  }

  cout << a.at(count+K-1)<<endl;

  //cout << goal << endl;

}


Compiler output:
a.cc: In function 'int main()':
a.cc:29:29: error: no match for 'operator=' (operand types are 'std::vector<int>' and 'void')
   29 |   b = sort(a.begin(),a.end());
      |                             ^
In file included from /usr/include/c++/14/vector:72,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/vector.tcc:210:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]'
  210 |     vector<_Tp, _Alloc>::
      |     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:211:42: note:   no known conversion for argument 1 from 'void' to 'const std::vector<int>&'
  211 |     operator=(const vector<_Tp, _Alloc>& __x)
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from /usr/include/c++/14/vector:66:
/usr/include/c++/14/bits/stl_vector.h:766:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = int; _Alloc = std::allocator<int>]'
  766 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:766:26: note:   no known conversion for argument 1 from 'void' to 'std::vector<int>&&'
  766 |       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
      |                 ~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:788:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>]'
  788 |       operator=(initializer_list<value_type> __l)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:788:46: note:   no known conversion for argument 1 from 'void' to 'std::initializer_list<int>'
  788 |       operator=(initializer_list<value_type> __l)
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
a.cc:44:26: error: 'j' was not declared in this scope
   44 |       if(a.at(i)==a.at(i+j)){
      |                          ^