2615Network Connections

2615   Network Connections

题目描述

Bob, who is a network administrator, supervises a network of computers. He is keeping a log connections between the computers in the network. Each connection is bi-directional. Two computers are interconnected if they are directly connected or if they are interconnected with the same computer. Occasionally, Bob has to decide, quickly, whether two given computers are connected, directly or indirectly, according to the log information.

Write a program which based on information input from a text file counts the number of successful and the number of unsuccessful answers to the questions of the kind :is computeri interconnected with computerj ?

输入格式:

The program reads data from a text file, as follows:

1.The number of computers in the network (a strictly positive integer);
2.A list of pairs of the form:
(a)  c computeri computerj, where computeri and computerj are integers from 1 to no_of_computers . A pair of this form shows that computeri and computerj get interconnected.
(b)   q computeri computerj, where computeri and computerj are integers from 1 to no_of_computers. A pair of this form stands for the question: is computeri interconnected with computerj?

Each pair is on a separate line. Pairs can appear in any order, regardless of their type. The log is updated after each pair of type (a) and each pair of type (b) is processed according to the current network configuration.


For example, the input file illustrated in the sample below corresponds to a network of 10 computers and 7 pairs. There are N1 successfully answered questions and N2 unsuccessfully answered questions.

输出格式:

The program prints these two numbers to the standard output on the same line, in the order: successful answers, unsuccessful answers, as shown in the sample output.

输入样例 复制
10
c 1 5
c 2 7
q 7 1
c 3 9
q 9 6
c 2 5
q 7 5
输出样例 复制
1,2

说明

0
16
通过提交
时空限制1000ms/128mb
题目来源
评测方式在线评测
题目类型
难        度