前五个测试点WA
#include<bits/stdc++.h>
using namespace std;
int a,b,x[500];
bool vis[500];
int q,p;
int N;
struct g{
int s,t;
};
int bfs(){
if(a==b){
return 0;
}
queue<g> js;
js.push({a,0});
vis[a]=1;
while(js.size()){
g head=js.front();
js.pop();
int s=head.s,t=head.t;
if(s==b){
return t;
}
int nx=s+x[s];
if(nx<=b&&nx>=0&&vis[nx]==0){
js.push({nx,t+1});
vis[nx]=1;
}
nx=s-x[s];
if(nx<=b&&nx>=0&&vis[nx]==0){
js.push({nx,t+1});
vis[nx]=1;
}
}
return -1;
}
int main()
{
cin>>N>>a>>b;
for(int i=1;i<=N;i++) cin>>x[i];
cout<<bfs();
return 0;
}