#C11532. Teleportation Path Problem
Teleportation Path Problem
Teleportation Path Problem
You are given N houses numbered from 1 to N. Each house i is equipped with a teleporter with a fixed jump length A[i] and a status indicator T[i] where 1 indicates the teleporter is functional and 0 indicates it is broken. From any house i, you can jump either to house i + A[i] or i - A[i], provided that the destination index is within the range \(1 \leq i \leq N\) and the teleporter at the destination is functional (i.e. T value is 1).
Your task is to determine whether it is possible to reach house Y starting from house X using only the functional teleporters.
Note: Convert the house indices to 0-indexed when processing the input if needed.
inputFormat
The input is given through standard input (stdin) and has the following format:
- An integer \(N\) representing the number of houses.
- A line with \(N\) space-separated integers representing the array A, where A[i] is the jump length at house i+1.
- A line with \(N\) space-separated integers representing the array T, where T[i] is 1 if the teleporter at house i+1 is functional, otherwise 0.
- A line with two space-separated integers X and Y representing the starting house and the destination house respectively.
outputFormat
Output a single line to standard output (stdout) containing either YES
if it is possible to reach house Y from house X, or NO
if it is not possible.
5
2 3 1 2 2
1 1 1 0 1
1 5
YES