Language: C++

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

#define pi 3.14159265358979323846264338327950L

/*#include <bits/stdc++.h>
#include <vector>
#include <stack>

using namespace std;


 bool comp(int a, int b){
    return (a < b);
}

int main(){

 int t;
 cin>>t;

 while(t--){

    int n,k,x; cin>>n>>k;

      int a[n],b[n];

    for(int i=0;i<n;i++)
        cin>>a[i];


    for(int j=0;j<n;j++)
      cin>>b[j];


    sort(a,a+n);
    sort(b,b+n,greater<int>());


     int* maxi;
    maxi = std::max_element(b, b+n, comp);

      int sum=0,lin=0;

  for(int i=0;i<n;i++)
    {
      if(lin < k){
     if(*maxi > a[i]){
        swap(a[i],*maxi);
         lin++;
         maxi = max_element(b, b + n,comp); }
      }
      if(lin > k)
        break;

   }

       for(int j=0;j<n;j++){
        sum += a[j];}


     cout<<sum<<endl;
 }


return 0;
}





int main(){

 int n = 4,flag = 0;
 set<char>ani;
  char a[4][4];

   for(int i=0;i<4;i++){
    for(int j=0;j<4;j++){
      cin>>a[i][j];
      ani.insert(a[i][j]);
       }
   }

   if(ani.size() == 1)
    cout<<"YES"<<endl;
   else {
  for(int i=0;i<=2;i++){
    for(int j=0;j<=2;j++){

        if(a[i][j] == '.' && a[i][j+1] == '#' && a[i+1][j] == '#' && a[i+1][j+1] == '#'
           || a[i][j] == '#' && a[i][j+1] == '.' && a[i+1][j] == '#' && a[i+1][j+1] == '#'
           || a[i][j] == '#' && a[i][j+1] == '#' &&a[i+1][j] == '.' && a[i+1][j+1] == '#'
           || a[i][j] == '#' && a[i][j+1] == '#' && a[i+1][j] == '#' && a[i+1][j+1] == '.'
           || a[i][j] == '#' && a[i][j+1] == '#' && a[i+1][j] == '#' && a[i+1][j+1] == '#' ){
                   flag = 1;
                 break; }
        if(a[i][j] == '#' && a[i][j+1] == '.' && a[i+1][j] == '.' && a[i+1][j+1] == '.'
           || a[i][j] == '.' && a[i][j+1] == '#' && a[i+1][j] == '.' && a[i+1][j+1] == '.'
           || a[i][j] == '.' && a[i][j+1] == '.' &&a[i+1][j] == '#' && a[i+1][j+1] == '.'
           || a[i][j] == '.' && a[i][j+1] == '.' && a[i+1][j] == '.' && a[i+1][j+1] == '#'
           || a[i][j] == '.' && a[i][j+1] == '.' && a[i+1][j] == '.' && a[i+1][j+1] == '.'){
                   flag = 1;
                 break; }
    }
  }

  if(flag == 0) cout<<"NO"<<endl;
  else cout<<"YES"<<endl;

   }

   ani.clear();

return 0;
}




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

#define pi 3.14159265358979323846264338327950L

int main(){

int a,b,h,m;

 cin>>a>>b>>h>>m;

 //long double rad = 2 * pi * ( ((long double)H/12.0+ ( (long double) M/60.0)/12.0 )- (long double) M/60.0 );

 long double rads = pi * 2 * (
 (long double)h / 12.0 + ((long double)m / 60.0) / 12.0 - (long
double)m / 60.0);


  long double ans = (long double)(a * a + b * b) - (long double)(2 * a *
b) * cosl(rads);

cout<<sqrtl(ans)<<endl;



return 0;
 }


int main(){

 int n,x,a; cin>>n;

 vector<int>das;

 for(int i=0;i<n;i++){
    cin>>x;
    das.push_back(x--); }

 int now=0,c=0;

 for(;;){

    if(now == 1){
        cout<<c<<endl;
        break; }

    if(c>=n){
        cout<<"-1"<<endl;
        break; }

    c++;
  now = v[now];
 }

return 0;
}

*/
int main(){

 int n,x,now=0,c=0;
 cin>>n;

 vector<int>das;

 for(int i=0;i<n;i++){
    cin>>x;
    v.push_back(--x);
 }

 for(;;){

    if(now == 1){
        cout<<c<<endl;
        break; }
    if(c>=n){
        cout<<"-1"<<endl;
        break; }

    c++;
    now = v[now];
 }


return 0;
}




























Compiler output:
a.cc: In function 'int main()':
a.cc:194:5: error: 'v' was not declared in this scope
  194 |     v.push_back(--x);
      |     ^
a.cc:207:11: error: 'v' was not declared in this scope
  207 |     now = v[now];
      |           ^