#include<iostream>
#include<queue>
using namespace std;
struct node{
int x,y;
};
queue <node> q;
int n,a,b,k[205],xnew,ynew;
bool vis[205];
int bfs()
{
q.push({a,0});
vis[a]=true;
while (!q.empty())
{
int x=q.front().x,y=q.front().y;
if (x==b) return y;
q.pop();
xnew=x+k[x];
ynew=y+1;
if (xnew>0 && xnew<=n && vis[xnew]==false)
{
vis[xnew]=true;
q.push({xnew,ynew});
}
xnew=x-k[x];
ynew=y+1;
if (xnew>0 && xnew<=n && vis[xnew]==false)
{
vis[xnew]=true;
q.push({xnew,ynew});
}
}
return -1;
}
int main()
{
cin>>n>>a>>b;
for (int i=1;i<=n;i++)
{
cin>>k[i];
vis[i]=false;
}
cout<<bfs();
return 0;
}
但运行时间长