#P2189. 小 Z 的传感器
小 Z 的传感器
Description
As we all know, Xiao Z lives in a mansion with rooms, connected by passages (the house is connected).
One day, while Xiao Z was away, Xiao Y decided to pay a secret visit and planned to visit each room at least once. Unfortunately, of the rooms are equipped with sensors, each of which returns a message the first time someone visits it.
When Xiao Z came home, he found that Xiao Y had been there, and Xiao Y truthfully told him that he visited each room at least once.
However, after carefully examining the order in which the sensors returned messages, Xiao Z suspected that some sensors might have delayed reporting.
To test his hypothesis, including that time, he had Xiao Y come to his house a total of times. He wants to determine whether the order of sensor messages for each visit could possibly occur, and asks you to help.
Input Format
The first line contains four integers .
Each of the next lines contains two integers , indicating that rooms and are connected by a bidirectional passage.
Each of the next lines contains integers, representing the indices of the rooms with sensors, in the order their messages were returned.
Output Format
Output lines. Each line contains the string Yes or No, indicating whether the given order of sensor messages could occur.
5 5 3 2
1 2
2 3
3 1
1 4
4 5
4 2 1
4 1 2
No
Yes
Hint
Sample explanation:
For the first query, must pass through , so the answer is No.
For the second query, the path matches the given record, so the answer is Yes.
Constraints:
For of the testdata, .
For of the testdata, .
For of the testdata, , , .
For of the testdata, , , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号