CF292B.Network Topology

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution.

Polycarpus continues working as a system administrator in a large corporation. The computer network of this corporation consists of n computers, some of them are connected by a cable. The computers are indexed by integers from 1 to n. It's known that any two computers connected by cable directly or through other computers

Polycarpus decided to find out the network's topology. A network topology is the way of describing the network configuration, the scheme that shows the location and the connections of network devices.

Polycarpus knows three main network topologies: bus, ring and star. A bus is the topology that represents a shared cable with all computers connected with it. In the ring topology the cable connects each computer only with two other ones. A star is the topology where all computers of a network are connected to the single central node.

Let's represent each of these network topologies as a connected non-directed graph. A bus is a connected graph that is the only path, that is, the graph where all nodes are connected with two other ones except for some two nodes that are the beginning and the end of the path. A ring is a connected graph, where all nodes are connected with two other ones. A star is a connected graph, where a single central node is singled out and connected with all other nodes. For clarifications, see the picture.

(1) — bus, (2) — ring, (3) — star

You've got a connected non-directed graph that characterizes the computer network in Polycarpus' corporation. Help him find out, which topology type the given network is. If that is impossible to do, say that the network's topology is unknown.

本题采用简化的网络拓扑模型,请仔细阅读题目描述,并在开发解法时将其作为正式文档使用。

Polycarpus 继续在一家大型企业担任系统管理员。该企业的计算机网络由 nn 台计算机组成,其中部分计算机通过网线直接相连。这些计算机按整数编号,编号范围为 11 到 nn。已知任意两台计算机之间均存在一条路径(可直接连接,也可通过其他计算机中转)。

Polycarpus 决定分析该网络的拓扑结构。网络拓扑是指对网络配置的描述方式,即一种展示网络设备位置及其连接关系的示意图。

Polycarpus 熟悉三种主要的网络拓扑:总线型(bus)、环型(ring)和星型(star)。总线型拓扑表现为一根共享的主干电缆,所有计算机均连接到该电缆上;环型拓扑中,每台计算机仅与另外两台计算机相连;星型拓扑则以一个中心节点为核心,网络中所有其他计算机均直接连接至该中心节点。

我们可将上述每种网络拓扑表示为一个连通的无向图。总线型拓扑对应一个连通图,且该图恰好构成一条路径——即图中除两个端点外,其余所有节点的度均为 22;环型拓扑对应一个连通图,其中每个节点的度均为 22;星型拓扑对应一个连通图,其中存在唯一一个中心节点,它与其余所有节点均相连,而其余节点彼此之间均不相连。为便于理解,参见下图:

(1)——总线型,(2)——环型,(3)——星型

现给定一个刻画 Polycarpus 所在企业计算机网络的连通无向图。请帮助他判断该网络属于上述哪一类拓扑结构。若无法判定,则输出“网络拓扑未知”。

输入格式

The first line contains two space-separated integers n and m (4 ≤ n ≤ 105; 3 ≤ m ≤ 105) — the number of nodes and edges in the graph, correspondingly. Next m lines contain the description of the graph's edges. The i-th line contains a space-separated pair of integers x__i, y__i (1 ≤ x__i, y__i ≤ n) — the numbers of nodes that are connected by the i-the edge.

It is guaranteed that the given graph is connected. There is at most one edge between any two nodes. No edge connects a node with itself.

第一行包含两个以空格分隔的整数 nn 和 mm(4 ≤ n ≤ 1054 \leq n \leq 10^5;3 ≤ m ≤ 1053 \leq m \leq 10^5),分别表示图中的节点数和边数。接下来的 mm 行描述图的边。第 ii 行包含一对以空格分隔的整数 xix_i, yiy_i(1 ≤ xi, yi ≤ n1 \leq x_i, y_i \leq n),表示第 ii 条边所连接的两个节点的编号。

保证给定图是连通的。任意两个节点之间至多存在一条边,且不存在连接节点自身的边。

输出格式

In a single line print the network topology name of the given graph. If the answer is the bus, print "bus topology" (without the quotes), if the answer is the ring, print "ring topology" (without the quotes), if the answer is the star, print "star topology" (without the quotes). If no answer fits, print "unknown topology" (without the quotes).

在一行中输出给定图的网络拓扑结构名称。若答案为总线型,输出 bus topology(不带引号);若答案为环型,输出 ring topology(不带引号);若答案为星型,输出 star topology(不带引号)。若无匹配答案,则输出 unknown topology(不带引号)。

输入输出样例

  • 输入#1

    4 3
    1 2
    2 3
    3 4

    输出#1

    bus topology
  • 输入#2

    4 4
    1 2
    2 3
    3 4
    4 1

    输出#2

    ring topology
  • 输入#3

    4 3
    1 2
    1 3
    1 4

    输出#3

    star topology
  • 输入#4

    4 4
    1 2
    2 3
    3 1
    1 4

    输出#4

    unknown topology

输入解题思路,AI测评打分。不知道怎么写?

首页