#include <iostream>
#include <queue>
#include <cstring>
#define x first
#define y second
using namespace std;
const int N=210;
int g[N];
int st[N];
typedef pair<int,int>PII;
int n;
void bfs(int start,int end)
{
queue<PII>q;
q.push({start,g[start]});
st[start]=0;
while(q.size())
{
auto t=q.front();
q.pop();
int a=t.x-g[t.x],b=t.x+g[t.x];
if(a>=1&&st[a]==-1){
q.push({a,g[a]});
st[a]=st[t.x]+1;
}
if(b<=n&&st[b]==-1){
q.push({b,g[b]});
st[b]=st[t.x]+1;
}
}
}
int main()
{
int a,b;
cin>>n>>a>>b;
for(int i=1;i<=n;i++) cin>>g[i];
memset(st,-1,sizeof st);
bfs(a,b);
cout<<st[b];
return 0;
}
0 回复
0 转发
0 喜欢
4 阅读



