#P14480. 化作彗星
化作彗星
Description
To recreate the comet of that day, Nana and Lily need to use specific number pairs to transform one sequence into another.
Nana has a sequence of length . Lily can choose an index each time, and then operate .
The chosen must satisfy . Lily finally needs to transform into another sequence of length .
Here, Nana will give an undirected graph with vertices and edges. It is not guaranteed that there are no multiple edges or self-loops. Then if and only if there is an edge between and in the graph. Note that if there is a self-loop at (an edge from to ), then ; otherwise, .
Lily is not very concerned about the construction of the solution, so she wants you to answer for multiple test cases whether can be transformed into another sequence of length .
Input Format
Each data point starts with three integers .
The first lines, the -th line has two integers indicating the -th edge connects .
Then, there are test cases.
Each test case input has three lines:
- The first line is an integer .
- The second line is a sequence of length , where the -th number is .
- The third line is a sequence of length , where the -th number is .
Output Format
For each test case, output one line with a string. If it is possible to transform into , output YES; otherwise, output NO.
1 2 2
1 2
6
1 1 2 1 2 2
2 1 1 2 2 1
2
2 2
1 2
YES
NO
Hint
Sample Explanation
For the first sample, we can operate as follows:
- Choose , the sequence becomes .
- Choose , the sequence becomes .
- Choose , the sequence becomes .
- Choose , the sequence becomes .
For the second sample, clearly you cannot perform the first operation. So it is impossible.
Data Range
| Subtask | Data Range | Special Constraints | Score |
|---|---|---|---|
| The graph is connected | |||
| The graph is a forest | |||
| None |
This problem uses subtask bundling. You must pass all test points in a subtask to get the corresponding score.
For all data, , , , , .
It is guaranteed that . The graph is not guaranteed to be without multiple edges or self-loops.
京公网安备 11011102002149号