#include <bits/stdc++.h>
using namespace std;
int n,s,t;
vector<int>a[205];
bitset<205> vis;
int dx[2]={1,-1};
bool judge(int x){
return x>=1&&x<=n;
}
struct node{
int x,step;
};
int main(){
scanf("%d%d%d",&n,&s,&t);
for(int i=1;i<=n;i++){
int x;
scanf("%d",&x);
for(int j=0;j<2;j++){
int r=i+x*dx[j];
if(judge(r))a[i].push_back(r);
}
}
if(s==t){
printf("0\n");
return 0;
}
queue<node>q;
node r;
r.x=s;
r.step=0;
vis[r.x]=true;
q.push(r);
while(!q.empty()){
node k=q.front();q.pop();
if(k.x==t){
printf("%d\n",k.step);
return 0;
}
int len=a[k.x].size();
for(int i=0;i<len;i++){
int v=a[k.x][i];
if(vis[v])continue;
node tmp;
tmp.x=v;
tmp.step=k.step+1;
q.push(tmp);
vis[k.x]=true;
}
}
printf("-1\n");
return 0;
}
写了一个bfs,不开O2 第一个点TLE O2开了MLE