The Psychic Type
Practice
3.4 (60 votes)
Ad Hoc
Basic programming
Easy
Implementation
Problem
94% Success 19813 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Alakazam has the unique ability to teleport itself during fights. He has realized that he can use this ability not just in Poke'mon fights, but also during real time manipulation of arrays. Abra, his non-evolution form has an interesting array of N integers, A1, A2, ... , AN-1, AN.

Since, Alakazam wants to try his teleporation power on arrays too, he decides to formalize it: he can move from any position i to a position \(A[i]\) in any array of the world. Now, he is currently standing at a position he calls S. He wants you to figure out if he can reach the position E.

Input format:
The first line consists of a single integer N. The second line consists of N integers A1, A2, ... , AN-1, AN, which are separated by a space. The next line consists of two integers S and E.

Output format:
Print Yes if he can reach the position E starting from position S, else print No.

Constraints:
1 ≤ N ≤ 1000
1 ≤ Ai ≤ N
1 ≤ S, E ≤ N

Reference:
enter image description here

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
25 votes
Tags:
ApprovedEasy
Points:20
264 votes
Tags:
ApprovedBasic ProgrammingEasyOpen
Points:20
4 votes
Tags:
Basic ProgrammingBasics of ImplementationEasyImplementationhiringobservation