#P2189. 小 Z 的传感器

小 Z 的传感器

Description

As we all know, Xiao Z lives in a mansion with nn rooms, connected by mm 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, kk 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 qq 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 n,m,k,qn, m, k, q.

Each of the next mm lines contains two integers x,yx, y, indicating that rooms xx and yy are connected by a bidirectional passage.

Each of the next qq lines contains kk integers, representing the indices of the rooms with sensors, in the order their messages were returned.

Output Format

Output qq 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, 424 \to 2 must pass through 11, so the answer is No.

For the second query, the path 454132134 \to 5 \to 4 \to 1 \to 3 \to 2 \to 1 \to 3 matches the given record, so the answer is Yes.


Constraints:

For 10%10\% of the testdata, n2n \le 2.

For 30%30\% of the testdata, n3n \le 3.

For 60%60\% of the testdata, n10000n \le 10000, m20000m \le 20000, k10k \le 10.

For 100%100\% of the testdata, 1kn1051 \le k \le n \le 10^5, 1m2×1051 \le m \le 2 \times 10^5, 1q51 \le q \le 5, 1x,yn1 \le x, y \le n, xyx \ne y.

Translated by ChatGPT 5