Problem F
Quantum Superposition
Through quantum superposition, you are in two universes at the same time. Each universe can be represented as a directed acyclic graph. You begin at the start vertices in each universe and your goal is to reach the end vertices. Now, you are wondering, can you reach the end vertices in both universes where the sum of steps made in each universe is exactly equal to a given number?
Input
The first line contains
Each of the next
Each of the next
There will not be duplicate edges. It is guaranteed that the universes are acyclic, and there exists a path from start to end vertex in each universe.
The next line contains
Output
For each query, output “Yes” if it is possible to reach the end vertices in both universes where the sum of steps made in each universe is exactly equal to the given query, or “No” otherwise.
Sample Input 1 | Sample Output 1 |
---|---|
3 2 3 1 1 2 1 3 2 3 1 2 5 0 1 2 3 4 |
No No Yes Yes No |