#include<iostream>
#include<queue>
struct coore{
int fl,nu;
};
int k[500];
bool vis[500];
using namespace std;
int main()
{
queue<coore> q;
int a,b,n,t=0;
cin>>n>>a>>b;
coore tmp={a,0};
for(int i=1;i<=n;i++)scanf("%d",&k[i]);
q.push(tmp);
coore x;
while(!q.empty())
{
x=q.front();
q.pop();
if(x.fl-k[x.fl]>0&&!vis[x.fl-k[x.fl]])
{
t++;
q.push({x.fl-k[x.fl],t});
vis[x.fl-k[x.fl]]=1;
}
if(x.fl+k[x.fl]<=n&&!vis[x.fl+k[x.fl]])
{
t++;
q.push({x.fl+k[x.fl],t});
vis[x.fl+k[x.fl]]=1;
}
}
if(x.fl==b)printf("%d",x.nu);
else cout<<"-1";
return 0;
}
结果很奇葩,求dalao们帮蒟蒻一把好吗