/*
Strange elevator (normal)
Time Limit: 1000 ms memory limit: 65536 K
Total submit: 200 accepted: 63
Description
Well, one day I dreamed of a strange elevator. The elevator is available on each floor of the building, and there is a digital KI (0 <= Ki <= N) on floor I (1 <= I <= N ). The elevator has only four buttons: On, off, up, down. The upper and lower layers are equal to the number on the current floor. Of course, if the requirements cannot be met, the corresponding button will fail. For example, 3 3 1 2 5 represents KI (k1 = 3, K2 = 3 ,......), From the first floor. On the first floor, you can press "up" to go to the fourth floor. clicking "down" does not work because there is no-2 floor. How many buttons should be pushed from building a to Building B?
Input
There are two rows in the input file. The first act is a positive integer separated by spaces, indicating N, a, B (1 ≤ n ≤ 200, 1 ≤ a, B ≤ n ), the second act is n positive integers separated by spaces, representing Ki.
Output
The output file contains only one line, that is, the minimum number of buttons. If the key cannot be reached, the output is-1.
Sample Input
5 1 5
3 3 1 2 5
Sample output
3
*/
# Include <stdio. h>
# Deprecision Max 501
Int A, B, N;
Int V [Max], flag = 0;
Void trytofind (int x, int total)
{
If (X-V [x] = B | x + V [x] = B)
{
If (total <flag | flag = 0)
Flag = total;
}
Else
{
If (x + V [x] <= N)
Trytofind (x + V [X], total + 1 );
If (X-V [x]> = 1)
Trytofind (X-V [X], total + 1 );
}
}
Int main (void)
{
Int I, J, K;
Scanf ("% d", & N, & A, & B );
For (I = 1; I <= N; I ++)
Scanf ("% d", & V [I]);
Trytofind (A, 1 );
If (FLAG)
Printf ("% d", flag );
Else
Printf ("-1 ");
System ("pause ");
Return 0;
}