#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=210;
int n,A,B,a[N],ans=1;
bool vis[N];
struct node{
int k,num;
};
int bfs(int A){
queue<node> q;
int t=A+a[A];
if(t>0&&t<=n){
q.push({t,1});
vis[t]=1;
}
t=A-a[A];
if(t>0&&t<=n){
q.push({t,1});
vis[t]=1;
}
while(!q.empty()){
t=q.front().k;
if(t==B) return ans;
if(ans==q.front().num) ans++;
q.pop();
int w=t+a[t];
if(w>0&&w<=n&&!vis[w]){
q.push({w,ans});
vis[w]=1;
}
w=t-a[t];
if(w>0&&w<=n&&!vis[w]){
q.push({w,ans});
vis[w]=1;
}
}
return -1;
}
signed main(){
cin>>n>>A>>B;
for(int i=1;i<=n;++i) cin>>a[i];
if(A==B) cout<<0;
else cout<<bfs(A);
return 0;
}
#15测试点:
#15输入:
200 1 200
1 1 26 7 9 21 10 5 12 13 3 15 3 26 2 9 28 12 24 10 21 26 22 10 5 10 14 8 25 9 15 5 27 9 24 30 15 27 25 1 5 5 16 1 18 1 24 20 24 22 17 7 21 18 29 20 30 8 21 9 3 24 15 27 16 18 29 21 11 1 22 30 24 23 6 5 28 24 18 26 21 9 3 19 9 27 5 9 17 29 6 5 9 6 18 15 9 5 19 23 23 3 3 2 4 24 25 12 19 14 23 15 11 25 25 5 3 3 2 6 21 7 18 8 11 26 10 10 20 21 28 10 15 9 24 23 17 22 13 17 18 27 21 4 15 13 4 2 17 21 3 28 26 21 28 9 22 23 15 20 5 7 29 11 4 30 10 2 4 27 17 21 4 21 1 10 28 17 10 14 28 11 11 15 3 26 23 6 28 15 4 27 13 7 25 18 3 19 28 0
输出:
17
我的输出:
18