当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

2838:Graph Connectivity

题目描述
Let us consider an undirected graph G = < V, E >. At first there is no edge in the graph. You are to write a program to calculate the connectivity of two different vertices. Your program should maintain the functions inserting or deleting an edge.
输入解释
The first line of the input contains an integer numbers N (2 <= N <= 1000) -- the number of vertices in G. The second line contains the number of commands Q (1 <= Q <= 20000). Then the following Q lines describe each command, and there are three kinds of commands:

I u v: Insert an edge (u, v). And we guarantee that there is no edge between nodes u and v, when you face this command.
D u v: Delete an existed edge (u, v). And we guarantee that there is an edge between nodes u and v, when you face this command.
Q u v: A querying command to ask the connectivity between nodes u and v.

You should notice that the nodes are numbered from 1 to N.
输出解释
Output one line for each querying command. Print "Y" if two vertices are connected or print "N" otherwise.
输入样例
3 
7
Q 1 2
I 1 2
I 2 3
Q 1 3
D 1 2
Q 1 3
Q 1 1
输出样例
N
Y
N
Y
来自北京大学POJ的附加信息
Case time limit(单组数据时间限制) 3000MS

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-2838

最后修改于 2020-10-29T06:45:29+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
8000 131072