Hide

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 1N1,N21000, the number of vertices in each universe, and 0M1,M22000, the number of edges in each universe. In both universes, vertex 1 is the start vertex. Vertices N1 and N2 are the end vertices in each respective universe.

Each of the next M1 lines contains two numbers 1u,vN1, indicating a directed edge from vertex u to vertex v in universe 1.

Each of the next M2 lines contains two numbers 1u,vN2, indicating a directed edge from vertex u to vertex v in universe 2.

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 1Q2000, the number of queries. Each query consists of a line with a single integer 0q2000 that is the sum of steps made in each universe.

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
Hide

Please log in to submit a solution to this problem

Log in