B. Network Topology

本文介绍了一种通过分析图中节点的连接方式来识别网络拓扑类型的方法,包括总线型、环型和星型拓扑,并提供了一个具体的实现示例。

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 ncomputers, 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.

Input

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 xiyi (1 ≤ xi, yi ≤ 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.

Output

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).

Sample test(s)
input
4 3
1 2
2 3
3 4
output
bus topology
input
4 4
1 2
2 3
3 4
4 1
output
ring topology
input
4 3
1 2
1 3
1 4
output
star topology
input
4 4
1 2
2 3
3 1
1 4
output
unknown topology

解题说明:此题是给出一个图的结构,判断属于那种网络拓扑(总线,星,环)。在这里判断的标准就是每个顶点的度,如果度全都是2,那么就是环型;如果只有两个点度为1,其余点度为2,就为总线型;如果一个点度为n-1,其余的点度为1,那么就是星型;不符合条件的不知道。用数组a存放每个顶点的边数,用数组b来统计每个的顶点的度,最后判断b的取值即可。


#include <iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;

int a[111111],b[111111];

int main()
{
	int n,m;
	int x,y;
	int i;
	scanf("%d %d",&n,&m);
	for(i=0;i<m;i++)
	{
		scanf("%d %d",&x,&y);
		a[x]++;
		a[y]++;
	}
	for(i=1;i<=n;i++)	
	{	
		b[a[i]]++;
	}
	if(b[2]==n)
	{
		printf("ring topology\n");
	}
	else if(b[2]==n-2 && b[1]==2)
	{
		printf("bus topology\n");
	}
	else if(b[n-1]==1 && b[1]==n-1)
	{
		printf("star topology\n");
	}
	else 
	{
		printf("unknown topology\n");
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值