atcoder#ABC304E. [ABC304E] Good Graph
[ABC304E] Good Graph
Score : points
Problem Statement
You are given an undirected graph with vertices and edges. For , the -th edge is an undirected edge connecting vertices and .
A graph with vertices is called good if the following condition holds for all :
- there is no path connecting vertices and in .
The given graph is good.
You are given independent questions. Answer all of them. For , the -th question is as follows.
- Is the graph obtained by adding an undirected edge connecting vertices and to the given graph good?
Constraints
- $i \neq j \implies \lbrace x_i, y_i \rbrace \neq \lbrace x_j, y_j \rbrace$
- For all , there is no path connecting vertices and .
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print lines.
For , the -th line should contain the answer to the -th question: Yes
if the graph is good, and No
otherwise.
6 6
1 2
2 3
2 3
3 1
5 4
5 5
3
1 5
2 6
4 3
4
2 5
2 6
5 6
5 4
No
No
Yes
Yes
- For the first question, the graph is not good because it has a path connecting vertices and . Therefore, print
No
. - For the second question, the graph is not good because it has a path connecting vertices and . Therefore, print
No
. - For the third question, the graph is good. Therefore, print
Yes
. - For the fourth question, the graph is good. Therefore, print
Yes
.
As seen in this sample input, note that the given graph may have self-loops or multi-edges.