#abc304e. E - Good Graph
E - Good Graph
Score : points
问题描述
给定一个包含 个顶点和 条边的无向图 。对于 ,第 条边是一条连接顶点 和 的无向边。
若一个包含 个顶点的图满足以下条件,则称其为 好 图:
- 对于所有 ,在图 中不存在一条连接顶点 和 的路径。
给定的图 是一个好图。
你将收到 个独立的问题,请逐一回答。对于 ,第 个问题是:
- 在给定的图 中添加一条连接顶点 和 的无向边得到的新图 是否仍是一个好图?
以上为通义千问 qwen-max 翻译,仅供参考。
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.
Sample Input 1
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
Sample Output 1
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.
update @ 2024/3/10 08:34:18