Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Language: Quick answer
Description 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? Input 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:
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. Output 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. Sample Input 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 Sample Output 2 , 2 Hint 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. Source |
[Submit] [Go Back] [Status] [Discuss]
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator