Fief
题号:NC239630
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 1024 M,其他语言2048 M
64bit IO Format: %lld

题目描述

Duke NIO had 2 sons, Antileaf and Fstqwq, and they would inherit Duke NIO's fief. Duke NIO's fief was composed of n cities, and there were m bi-direction roads connecting these cities. For fairness, Duke NIO made the following rules for Antileaf and Fstqwq when inheriting his fief:

Firstly, both Antileaf and Fstqwq could choose a favorite city.

Then, according to the two favorite cities, Duke NIO would make a list. The content of the list is his n cities, and the first item of the list is Antileaf's favorite city while the last item of the list is Fstqwq's favorite city.

After that, Antileaf and Fstqwq could begin to inherit his fief. The number of cities each one would get should be determined by drawing a lot. For instance, Antileaf would get the first a cities in NIO's list (a is uniformly random between 1 and n-1) while Fstqwq would get the last n-a cities.

After all the cities were assigned to his two sons, each son's fief should be a connected component.

However, he found that in some cases, he couldn't find a list that meet his requirement. He came out with some questions - if Antileaf chose city x as his favorite city and Fstqwq chose city y, could he always find a list such that Antileaf and Fstqwq's fief would be always connected regardless of the result of the lottery?

输入描述:

The first line contains two integers n and m (, ), denoting the number of cities and the number of roads. Then follows m lines, each line contains two integers u_i and v_i (, ), denotes the roads.

After that follows a line with a single integer q (), which denotes the number of NIO's queries. And then follows q lines, each line contains two integers x_i and y_i (, ), the meaning is described above.

输出描述:

Output q lines. For the i-th line, if the answer of the i-th query is true, print "YES" (excluding quotes), otherwise print "NO" (excluding quotes).
示例1

输入

复制
4 3
1 2
2 3
4 3
3
1 3
4 1
3 4

输出

复制
NO
YES
NO

说明

For the second query, the only valid list is [4, 3, 2, 1]
示例2

输入

复制
4 6
1 2
1 3
1 4
2 3
2 4
3 4
2
1 4
2 4

输出

复制
YES
YES

说明

For the first query, one of the valid list is [1, 3, 2, 4].

For the second query, one of the valid list is [2, 3, 1, 4].

备注:

For the second query in the first example, the only valid list is (4, 3, 2, 1).

For the first query in the second example, one valid list is (1, 3, 2, 4).

For the second query in the second example, one valid list is (2, 3, 1, 4).