Challenges

Rotate Array
You are given an array of N length. You have to rotate the array right...
Max. Marks: 6
Solved By : 983
Floating Number
Bob has a floating point number N. He wants to set the precision for 2...
Max. Marks: 4
Solved By : 4573
SwapMaster solves Symmetric Swap
The SwapMaster is known to be the greatest and fastest swapper of all ...
Max. Marks: 4
Solved By : 3957
String Matching
Cody has a sequence of characters N. He likes a sequence if it contain...
Max. Marks: 3
Solved By : 2125
Leap Year
Steve is playing a quiz game with his brother John. As Steve just lear...
Max. Marks: 6
Solved By : 3313
Project Teams
There are N students in a class and Teacher want to divide these stude...
Max. Marks: 5
Solved By : 4078
Circle of Numbers
All numbers in NumberLand are standing in a circle for a dancing cerem...
Max. Marks: 6
Solved By : 2815
Happy String
A happy string is a string in which each character is lexicographicall...
Max. Marks: 4
Solved By : 2099
Degree Celsius
Tom is a scientist. He uses huge machines for complex calculations. Th...
Max. Marks: 4
Solved By : 4761
Three's Company
This problem requires you to create a output string from input string ...
Max. Marks: 4
Solved By : 3135
Bourne's Supremacy
Please select a challenge
Problem Statement
Jason Bourne is a former spy who suffered from local amnesia and hence forgot who he was. After some time, he found a former colleague of his, Aaron, who was a spy just like him and that brought back some memories. He tried to contact him but he ran away, so Bourne placed a tracker on him. After a while, Aaron found the tracker and ditched it. Meanwhile, Bourne was analysing his moving patterns on a graph and found that he still followed an old trick to lose followers. All spies were given a list of numbers, arr, which expanded back to coordinates(latitude and longitude) using a decryption technique. Let us assume your current position is x, now you can go to position arr[x] and then to position arr[arr[x]] and henceforth. These help to keep your movements random. Now Bourne obviously knows his starting position and needs to catch up on him. So he decides instead of following the route, he would just intercept him at a point he knows he will definitely come to. Bourne doesn't have much time so asked you for help. You will be given a destination point and you need to find out if Aaron will reach there at sometime or not. NOTE: All indexes in the explanation were 1-based. For example, for N = 5 arr[] = 5 4 2 1 3 source = 1 , destination = 4 arr[1] = 5, arr[5] = 3, arr[3] = 2, arr[2] = 4 (reached destination) Hence, a person can go from 1 to 4 using this array.

Input
The first line of input contains T, the number of test cases. Each test case contains 3 lines: The first line contains N, the number of elements in the array. Next line contains N space-separated integers denoting elements of array. Next line contains 2 space-separated integers denoting source and destination

Output
For every test case, if a person can go from source to destination, print "Yes", else print "No", in a newline.

Constraints
1 ≤ T ≤ 20 1 ≤ N ≤ 1000 1 ≤ arr[i] ≤ N 1 ≤ source, destination ≤ N

Sample Input
1
5
5 4 2 1 3
1 4

Sample Output

Yes

Dcoded By: Mrudul Sankhere

Solved By: 283

Maximum Marks: 12