This is quite a straight-forward problem, but I chose to solve it in a more general way for C++ and Python just to show some of the quicks in submitting Python code with recursion. We are given integers $n, t$, with $3 \leq n \leq 3 \times 10^4$ and $2 \leq t \leq n$.
The second line has $n - 1$ integers, each $a_i$ for all $1 \leq i \leq n - 1$. At index $i$, we can jump forward $a_i$. Starting from index $0$, we want to know if it is possible to get to $t - 1$ (0-based). This can be done linearly, just follow the jumps from $0$ until $p \geq t - 1$, and if $p$ reaches $t - 1$ exactly, print YES otherwise NO (where $p$ is the position, initially $0$).
Or, you can model the problem as finding connected components using iterative search such as depth-first search, keeping track of which nodes have been visited. Since the search starts from only $0$, the target will be in our connected component once the search completes.
For Python, you may notice that this connected component approach gets a runtime error ( that is, if you
remove the threading and setrecursionlimit settings from the code below; code shown is accepted ),
even
with a correct implementation. The recursion limit for Python is quite low by default, but we can adjust it
in a
number of ways for CodeForces. One way is to use
threading.stack_size
for the stack size and
sys.setrecursionlimit
for the recursion depth. You will notice memory usage increase significantly for this approach on
CodeForces.
There are other tweaks you can do (search CodeForces forums for more information on this topic).
Although we got it to work this time, some problems just cannot be solved in time with Python. In those cases, you'll need to fallback on something else. Usually that means either C, C++, or Java.
For JavaScript, we use the "smarter" approach without the use of DFS traversal (it is a simple problem, after all). The code you see at the bottom is boilerplate to make the submission usable by CodeForces online judging system.