Challenges
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: 296
Maximum Marks: 12