Language: C++

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

int N;
long long int K;
int num = 1;//今いる町番号
int yukisaki = 0;
int time = 0;
int flag = 1;
int nikaime = 0;

int main() {
    cin >> N >> K;

    vector<int> vec(N);
    vector<int> sam(N);

    for (int i = 0; i < N; i++) {
        cin >> vec.at(i);
    }
    
    int k = 0;
    while (flag)

        yukisaki = vec.at(num-1);
        num = yukisaki;
        sam.at(i) = num;
        sort(begin(sam.at()),end(sam.at()));
        if(num == sam.at(i) && nikaime == 0) {
            time = k;
            nikaime = 1;
        }
        else if(num == sam.at(i) && nikaime == 1){
            time = k - time;
            flag = 0;
        }
        k++;

    }



    cout << vec.at(k-1+K%time) << endl;
  
}


Compiler output:
a.cc:8:5: error: 'int time' redeclared as different kind of entity
    8 | int time = 0;
      |     ^~~~
In file included from /usr/include/pthread.h:23,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr-default.h:35,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr.h:157,
                 from /usr/include/c++/14/ext/atomicity.h:35,
                 from /usr/include/c++/14/bits/ios_base.h:39,
                 from /usr/include/c++/14/streambuf:43,
                 from /usr/include/c++/14/bits/streambuf_iterator.h:35,
                 from /usr/include/c++/14/iterator:66,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:54,
                 from a.cc:1:
/usr/include/time.h:76:15: note: previous declaration 'time_t time(time_t*)'
   76 | extern time_t time (time_t *__timer) __THROW;
      |               ^~~~
a.cc: In function 'int main()':
a.cc:27:16: error: 'i' was not declared in this scope
   27 |         sam.at(i) = num;
      |                ^
a.cc:28:26: error: no matching function for call to 'std::vector<int>::at()'
   28 |         sort(begin(sam.at()),end(sam.at()));
      |                    ~~~~~~^~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53:
/usr/include/c++/14/bits/stl_vector.h:1180:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::at(size_type) [with _Tp = int; _Alloc = std::allocator<int>; reference = int&; size_type = long unsigned int]'
 1180 |       at(size_type __n)
      |       ^~
/usr/include/c++/14/bits/stl_vector.h:1180:7: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/stl_vector.h:1199:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::at(size_type) const [with _Tp = int; _Alloc = std::allocator<int>; const_reference = const int&; size_type = long unsigned int]'
 1199 |       at(size_type __n) const
      |       ^~
/usr/include/c++/14/bits/stl_vector.h:1199:7: note:   candidate expects 1 argument, 0 provided
a.cc:28:40: error: no matching function for call to 'std::vector<int>::at()'
   28 |         sort(begin(sam.at()),end(sam.at()));
      |                                  ~~~~~~^~
/usr/include/c++/14/bits/stl_vector.h:1180:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::at(size_type) [with _Tp = int; _Alloc = std::allocator<int>; reference = int&; size_type = long unsigned int]'
 1180 |       at(size_type __n)
      |       ^~
/usr/include/c++/14/bits/stl_vector.h:1180:7: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/stl_vector.h:1199:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::at(size_type) const [with _Tp = int; _Alloc = std::allocator<int>; const_reference = const int&; size_type = long unsigned int]'
 1199 |       at(size_type __n) const
      |       ^~
/usr/include/c++/14/bits/stl_vector.h:1199:7: note:   candidate expects 1 argument, 0 provided
a.cc:30:18: error: assignment of function 'time_t time(time_t*)'
   30 |             time = k;
      |             ~~~~~^~~
a.cc:34:22: error: invalid operands of types 'int' and 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'} to binary 'operator-'
   34 |             time = k - time;
      |                    ~ ^ ~~~~
      |                    |   |
      |                    int time_t(time_t*) noexcept {aka long int(long int*) noexcept}
a.cc: At global scope:
a.cc:43:5: error: 'cout' does not name a type
   43 |     cout << vec.at(k-1+K%time) << endl;
      |     ^~~~
a.cc:45:1: error: expected declaration before '}' token
   45 | }
      | ^