1555_NetworkConnections

2022-5-16 18:17| 发布者: Hocassian| 查看: 17| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-2-89503965902200-Problem List-采集的数据-后羿采集器.html

Pro.ID

1555

Title

Network Connections

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=1555

AC

0

Submit

13

Ratio

0.00%

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 131072/131072 K (Java/Others)
  • 描述

    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 first line of the input contains the number of dataset, and it's followed by a blank line. Each dataset is defined as follows:

    1. The number of computers in the network (a strictly positive integer);
    2. A list of pairs of the form:
    (a) ccomputericomputerj, 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) qcomputericomputerj, 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 ?

    There's a blank line between datasets.

    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.

    输出

    Description

    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 ?

    Input

    The first line of the input contains the number of dataset, and it's followed by a blank line. Each dataset is defined as follows:

    1. The number of computers in the network (a strictly positive integer);
    2. A list of pairs of the form:
    (a) ccomputericomputerj, 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) qcomputericomputerj, 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 ?

    There's a blank line between datasets.

    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.

    Output

    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. Print a blank line between datasets.

    Sample Input

    1

    10
    c 1 5
    c 2 7
    q 7 1
    c 3 9
    q 9 6
    c 2 5
    q 7 5

    Sample Output

    1, 2

    Source

    样例输入

    1

    10
    c 1 5
    c 2 7
    q 7 1
    c 3 9
    q 9 6
    c 2 5
    q 7 5

    样例输出

    1, 2

    提示

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部