The Circular jump (Lowe)

4

13 votes
Approved, Breadth First Search, Easy, Graphs
Problem

There are N chairs arranged around a circular table. Each chair has a number Numi written on it. Any person sitting on a chair i can jump Numi number of indices towards left or right, You are sitting on chair X and you have to reach chair Y. Tell the minimum number of jumps required by you. If its impossible to reach then print 1.

Example :- If your sitting on chair 4 and it has number 2 written on it then you can either jump to chair number 2 or chair number 6.

Constraints
1<=T<=100
1<=N<=104
1<=Numi<=109
1<=X,Y<=N

Format of the input file:
First line : T i.e number of testcases.
For each testcase :
First line : Three space separated integers N , X and Y.
Second line : N space separated integers denoting the chNum.

Format of the output file:
For each testcase print the answer in a separate line.

Sample Input
1
5 1 5
2 1 2 3 4
Sample Output
2
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For the given testcase we can jump from chair 1 to chair 3 and from chair 3 to chair 5 hence we can reach chair 5 in exactly 2 jumps.

Editor Image

?