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

建议使用的浏览器:

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

3908:Quick answer

题目描述
Joe is fond of computer games. Now, he must solve a puzzling situation. In front of his eyes lies a huge map with fortified towns. His enemy is a very powerful and tricky character who can connect and disconnect the towns by giving some commands. Two towns are connected if they have been directly connected or interconnected through some other connected towns at some moment in time. When a town is disconnected it gets isolated and clears its own connection history, not the connection history of the other towns. Each connection is bi-directional. Initially the towns are isolated. Joe is asked to answer quickly if two towns are connected, according to the history of the character’s commands.
Write a program which based on information input from a text file counts the number of yes answers and the number of no answers to questions of the kind: is towni connected with townj?
输入解释
Each data set in the file stands for a particular map and the associated character’s commands, as follows:
1) The number of towns on the map N (N ≤ 10000);
2) A list of commands of the form:


a) c towni townj, where towni and townj are integers from 1 to no_of_towns. The command means that towni and townj get connected.
b) d towni, where towni is an integer from 1 to no_of_towns. The command means that towni gets disconnected.
c) q towni townj, where towni and townj are integers from 1 to no_of_towns. The command stands for the question: is towni connected with townj?
d) e, that ends the list of commands


Each command is on a separate line. Commands (a), (b), (c) can appear in any order. The towns’ connectivity is updated after each command of type (a) or (b). Each command of type (c) is processed according to the current configuration.
输出解释
There are N1 yes answered questions and N2 no answered questions. The program prints these two numbers to the standard output on the same line, in the order: N1 , N2.
输入样例
4
c 1 2
c 3 4
q 1 3
c 2 3
q 1 4
d 2
q 4 1
q 2 4
e
输出样例
2 , 2
提示
For example, the input file illustrated in the figure corresponds to only one data set which stands for a map with 4 fortified towns. The character gives 9 commands. There are N1 yes answered questions and N2 no answered questions.

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

源链接: POJ-3908

最后修改于 2020-10-29T07:15:07+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 65536