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. [Image] (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 ≤ 10^5; 3 ≤ m ≤ 10^5) — 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.


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


-----Examples-----
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

Source: codeforces | Difficulty: EASY
Tags: Graph algorithms

Implementation


Solutions:
(n, m) = map(int, input().split())
d = {i: [] for i in range(1, n + 1)}
for _ in range(m):
	(a, b) = map(int, input().split())
	d[a].append(b)
	d[b].append(a)
c = 0
(one, two) = (0, 0)
star = 0
for i in d:
	if len(d[i]) == 1:
		c += 1
		one += 1
	elif len(d[i]) == 2:
		two += 1
	elif len(d[i]) == n - 1:
		star += 1
if c == n - 1 and star == 1:
	print('star topology')
elif one == 2 and two == n - 2:
	print('bus topology')
elif two == n:
	print('ring topology')
else:
	print('unknown topology')


(n, m) = map(int, input().split())
l = [0] * n
d = l[:]
for _ in range(m):
	(a, b) = map(int, input().split())
	l[a - 1] += 1
	l[b - 1] += 1
for i in l:
	d[i] += 1
if d[1] == 2 and d[2] == n - 2:
	print('bus topology')
elif d[2] == n:
	print('ring topology')
elif d[1] == n - 1 and d[n - 1] == 1:
	print('star topology')
else:
	print('unknown topology')


(n, m) = map(int, input().split())
if n == m or n == m + 1:
	s = [0] * n
	for _ in range(m):
		(a, b) = map(int, input().split())
		s[a - 1] += 1
		s[b - 1] += 1
	s = set(s)
	if s == {2}:
		print('ring topology')
	elif s == {1, 2}:
		print('bus topology')
	elif s == {1, m}:
		print('star topology')
	else:
		print('unknown topology')
else:
	print('unknown topology')
	exit(0)


(n, m) = [int(i) for i in input().split()]
graf = [[] for i in range(n + 1)]
for i in range(m):
	(k1, k2) = [int(i) for i in input().split()]
	graf[k1].append(k2)
	graf[k2].append(k1)
seks = [0, 0, 0]
for i in range(1, n + 1):
	if len(graf[i]) == 1 or len(graf[i]) == 2:
		seks[len(graf[i])] += 1
	else:
		seks[0] += 1
if seks[0] == 0 and seks[1] == 2:
	print('bus topology')
elif seks[0] == seks[1] == 0:
	print('ring topology')
elif seks[0] == 1 and seks[2] == 0:
	print('star topology')
else:
	print('unknown topology')


from collections import defaultdict
(n, m) = map(int, input().split())
d = defaultdict(list)
a = []
for i in range(m):
	(x, y) = map(int, input().split())
	d[x].append(y)
	d[y].append(x)
for i in range(1, n + 1):
	p = len(d[i])
	a.append(p)
flag = 0
mid = 0
start = 0
for i in range(0, n):
	if a[i] == 2:
		mid += 1
	elif a[i] == 1:
		start += 1
if mid == n - 2 and start == 2:
	flag = 2
tag = 0
for i in range(n):
	if a[i] == 2:
		tag = 2
	else:
		tag = 1
		break
sac = 0
p = max(a)
t = a.index(p)
for i in range(n):
	if i != t:
		if a[i] == 1:
			sac = 2
		else:
			sac = 1
			break
	if i == t:
		if p == n - 1:
			sac = 2
		else:
			sac = 1
			break
if flag == 2:
	print('bus topology')
elif tag == 2:
	print('ring topology')
elif sac == 2:
	print('star topology')
else:
	print('unknown topology')


(n, m) = map(int, input().split())
a = [0] * n
for i in range(m):
	(x, y) = map(int, input().split())
	a[x - 1] += 1
	a[y - 1] += 1
s = set(a)
if s == {2}:
	print('ring')
elif s == {1, 2}:
	print('bus')
elif s == {1, m}:
	print('star')
else:
	print('unknown')
print(' topology')


def checkTopology(network, n, e):
	if e == n - 1:
		if sum([len(y) == 1 for (x, y) in network.items()]) == 2:
			return 'bus'
		elif any([len(y) == e for (x, y) in network.items()]):
			return 'star'
	elif e == n:
		if all([len(y) == 2 for (x, y) in network.items()]):
			return 'ring'
	return 'unknown'
(nodes, edges) = [int(x) for x in input().split()]
connections = {}
for n in range(1, nodes + 1):
	connections[n] = []
for e in range(edges):
	(n, m) = [int(x) for x in input().split()]
	connections[n].append(m)
	connections[m].append(n)
print(checkTopology(connections, nodes, edges), 'topology')


def main():
	(n, m) = map(int, input().split())
	types = ['bus', 'ring', 'star', 'unknown']
	occ = [0] * n
	for i in range(m):
		(a, b) = map(int, input().split())
		occ[a - 1] += 1
		occ[b - 1] += 1
	cnt = [0] * 3
	for v in occ:
		cnt[min(2, v - 1)] += 1
	if cnt == [2, n - 2, 0]:
		res = types[0]
	elif cnt == [0, n, 0]:
		res = types[1]
	elif cnt == [n - 1, 0, 1]:
		res = types[2]
	else:
		res = types[3]
	print(res, 'topology')
main()


(n, e) = list(map(int, input().split()))
network = {}
arr = []
for i in range(e):
	(a, b) = map(int, input().split())
	if a in network:
		network[a].append(b)
	else:
		network[a] = [b]
	if b in network:
		network[b].append(a)
	else:
		network[b] = [a]
for k in network:
	arr.append(len(network[k]))
if arr.count(1) == 2 and arr.count(2) == n - 2:
	print('bus topology')
elif arr.count(2) == n:
	print('ring topology')
elif arr.count(n - 1) == 1 and arr.count(1) == n - 1:
	print('star topology')
else:
	print('unknown topology')


(n, m) = map(int, input().split())
graph = {}
for i in range(1, n + 1):
	graph[i] = []
for i in range(m):
	(u, v) = map(int, input().split())
	graph[u].append(v)
	graph[v].append(u)
c = 0
d = 0
for i in range(1, n + 1):
	if len(graph[i]) == 1:
		c = c + 1
	elif len(graph[i]) >= 2:
		d = d + 1
if m == n - 1 and c == 2 and (d == n - 2):
	print('bus topology')
elif c == 0 and d == n and (m == n):
	print('ring topology')
elif c == n - 1 and d == 1:
	print('star topology')
else:
	print('unknown topology')


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(m):
	(x, y) = map(int, input().split())
	g[x - 1].append(y - 1)
	g[y - 1].append(x - 1)

def ring(n, m, g):
	if all((len(l) == 2 for l in g)):
		return True
	else:
		return False

def star(n, m, g):
	return any((len(l) == m for l in g))

def bus(n, m, g):
	for node in range(3):
		if len(g[node]) == 2:
			break
	else:
		return False
	exit = 0
	visited = [0] * n
	visited[node] = 1
	nodes = [node]
	while nodes:
		cur = nodes.pop()
		count = 0
		for new_node in g[cur]:
			if not visited[new_node]:
				visited[new_node] = 1
				nodes.append(new_node)
				count += 1
		if count == 0:
			exit += 1
	return exit == 2
if m == n - 1 and bus(n, m, g):
	print('bus topology')
elif m == n and ring(n, m, g):
	print('ring topology')
elif m == n - 1 and star(n, m, g):
	print('star topology')
else:
	print('unknown topology')


def main():
	(n, m) = map(int, input().split())
	l = [0] * n
	for i in range(m):
		(a, b) = map(int, input().split())
		l[a - 1] += 1
		l[b - 1] += 1
	k_1 = 0
	k_2 = 0
	k_n = 0
	for i in range(n):
		if l[i] == 1:
			k_1 += 1
		elif l[i] == 2:
			k_2 += 1
		elif l[i] == n - 1:
			k_n += 1
	if k_1 == 2 and k_2 == n - 2:
		print('bus topology')
	elif k_2 == n:
		print('ring topology')
	elif k_1 == n - 1 and k_n == 1:
		print('star topology')
	else:
		print('unknown topology')
main()


from collections import Counter
(n, m) = map(int, input().split())
g = [[] for _ in range(n)]
for i in range(m):
	(x, y) = map(int, input().split())
	g[x - 1].append(y - 1)
	g[y - 1].append(x - 1)
bus = [2] * (n - 2) + [1] * 2
star = [1] * (n - 1) + [n - 1]
lns = [len(lst) for lst in g]
if lns == [2] * n:
	print('ring topology')
elif Counter(lns) == Counter(bus):
	print('bus topology')
elif Counter(lns) == Counter(star):
	print('star topology')
else:
	print('unknown topology')


(m, n) = [int(i) for i in input().split()]
adj = []
for i in range(m):
	adj.append([])
for i in range(n):
	(first, second) = [int(i) for i in input().split()]
	adj[first - 1].append(second)
	adj[second - 1].append(first)
vertices = m
edges = n
ones = 0
twos = 0
every = 0
if edges == vertices:
	for i in range(m):
		if len(adj[i]) == 1:
			ones += 1
		elif len(adj[i]) == 2:
			twos += 1
elif edges < vertices:
	for i in range(m):
		if len(adj[i]) == 1:
			ones += 1
		elif len(adj[i]) == 2:
			twos += 1
		elif len(adj[i]) == n:
			every += 1
if twos == m:
	print('ring topology')
elif ones == n and every == 1:
	print('star topology')
elif twos == m - 2 and ones == 2:
	print('bus topology')
else:
	print('unknown topology')


(n, m) = map(int, input().split())
A = [0] * n
for _ in range(m):
	(a, b) = map(int, input().split())
	A[a - 1] += 1
	A[b - 1] += 1
x = set(A)
if x == {2}:
	print('ring topology')
elif x == {1, 2}:
	print('bus topology')
elif x == {1, m}:
	print('star topology')
else:
	print('unknown topology')


import os
import sys
from io import BytesIO, IOBase
mod = 10 ** 9 + 7

def main():
	(n, m) = map(int, input().split())
	graph = [[] for _ in range(n + 1)]
	for _ in range(m):
		(a, b) = map(int, input().split())
		graph[a].append(b)
		graph[b].append(a)
	ans = 'unknown'
	(one, two, three) = (0, 0, 0)
	for _ in range(1, n + 1):
		if len(graph[_]) > 2:
			three += 1
		elif len(graph[_]) == 2:
			two += 1
		else:
			one += 1
	if three:
		if three == 1 and one == n - 1:
			ans = 'star'
	elif one:
		ans = 'bus'
	else:
		ans = 'ring'
	print(f'{ans} topology')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(m):
	(x, y) = map(int, input().split())
	g[x - 1].append(y - 1)
	g[y - 1].append(x - 1)
s = set()
for l in g:
	s.add(len(l))
if s == {2}:
	print('ring topology')
elif s == {1, 2}:
	print('bus topology')
elif s == {1, m}:
	print('star topology')
else:
	print('unknown topology')


(m, n) = map(int, input().split(' '))
li = [[] for r in range(m)]
for i in range(n):
	(x, y) = map(int, input().split(' '))
	li[x - 1].append(1)
	li[y - 1].append(1)
one = 0
two = 0
more = 0
for i in li:
	ans = len(i)
	if ans == 1:
		one += 1
	elif ans == 2:
		two += 1
	else:
		more += 1
if one == 2 and two == m - 2:
	print('bus topology')
elif two == m:
	print('ring topology')
elif one == m - 1 and more == 1:
	print('star topology')
else:
	print('unknown topology')


(n, m) = [int(x) for x in input().split()]
v = []
for i in range(n):
	ar = []
	v.append(ar)
for i in range(m):
	(p, q) = [int(x) for x in input().split()]
	v[p - 1].append(q)
	v[q - 1].append(p)
s = 0
t = 0
u = 0
for i in range(len(v)):
	if len(v[i]) == 1:
		s += 1
	elif len(v[i]) == 2:
		t += 1
	else:
		u += 1
if s == 2 and u == 0:
	print('bus topology')
elif s == 0 and u == 0:
	print('ring topology')
elif s == n - 1:
	print('star topology')
else:
	print('unknown topology')


def bus_topology(neigh):
	single_neighbors = 0
	for i in range(1, len(neigh)):
		if len(neigh[i]) == 1:
			single_neighbors += 1
		elif len(neigh[i]) > 2:
			return False
	if single_neighbors == 2:
		return True
	else:
		return False

def ring_topology(neigh):
	for i in range(1, len(neigh)):
		if len(neigh[i]) > 2:
			return False
	return True

def star_topology(neigh, n):
	centernode = 0
	for i in range(1, len(neigh)):
		if len(neigh[i]) == n - 1:
			centernode += 1
		elif len(neigh[i]) != 1:
			return False
	if centernode == 1:
		return True
	else:
		return False
(n, m) = [int(x) for x in input().split()]
neighbors = [[] for x in range(n + 1)]
for i in range(m):
	(u, v) = (int(x) for x in input().split())
	neighbors[u].append(v)
	neighbors[v].append(u)
if bus_topology(neighbors):
	print('bus topology')
elif ring_topology(neighbors):
	print('ring topology')
elif star_topology(neighbors, n):
	print('star topology')
else:
	print('unknown topology')


(n, m) = map(int, input().split())
d = [0] * (n + 1)
for i in range(m):
	(x, y) = map(int, input().split())
	d[x] += 1
	d[y] += 1
if d.count(1) == 2 and d.count(2) == n - 2:
	print('bus topology')
elif d.count(2) == n:
	print('ring topology')
elif d.count(1) == n - 1 and d.count(n - 1) == 1:
	print('star topology')
else:
	print('unknown topology')


import sys
import math
import string

def getRes(connections, n, m):
	bus = 0
	for i in range(1, n + 1):
		if connections[i] == 1:
			bus += 1
		elif connections[i] == n - 1 and m == n - 1:
			print('star topology')
			return
		elif connections[i] != 2:
			print('unknown topology')
			return
	if bus == 2:
		print('bus topology')
	else:
		print('ring topology')
	return
[n, m] = [int(i) for i in sys.stdin.readline().split()]
connections = [0 for x in range(n + 1)]
for i in range(m):
	[x, y] = [int(i) for i in sys.stdin.readline().split()]
	connections[x] += 1
	connections[y] += 1
getRes(connections, n, m)


(n, m) = map(int, input().split())
adj = [[] for i in range(n)]
for i in range(m):
	(u, v) = map(int, input().split())
	u -= 1
	v -= 1
	adj[u].append(v)
	adj[v].append(u)

def count(d):
	return len([1 for u in range(n) if len(adj[u]) == d])

def identify():
	if count(2) == n:
		return 'ring'
	elif count(n - 1) == 1 and count(1) == n - 1:
		return 'star'
	elif count(2) == n - 2 and count(1) == 2:
		return 'bus'
	else:
		return 'unknown'
print(identify(), 'topology')


import sys
from math import *

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return list(map(int, minp().split()))
(n, m) = mints()
e = [[] for i in range(n + 1)]

def isstar():
	c = None
	for i in range(1, n + 1):
		if len(e[i]) > 1:
			if c != None:
				return False
			c = i
	if c == None:
		return False
	return len(e[c]) == n - 1

def isbus():
	c = None
	for i in range(1, n + 1):
		if len(e[i]) == 1:
			c = i
	if c == None:
		return False
	cnt = 2
	p = c
	c = e[c][0]
	while len(e[c]) == 2:
		if e[c][0] == p:
			p = c
			c = e[c][1]
		else:
			p = c
			c = e[c][0]
	return len(e[c]) == 1

def isring():
	p = 1
	if len(e[1]) != 2:
		return False
	c = e[1][0]
	while len(e[c]) == 2 and c != 1:
		if e[c][0] == p:
			p = c
			c = e[c][1]
		else:
			p = c
			c = e[c][0]
	return c == 1
for i in range(m):
	(a, b) = mints()
	e[a].append(b)
	e[b].append(a)
if isstar():
	print('star topology')
elif isbus():
	print('bus topology')
elif isring():
	print('ring topology')
else:
	print('unknown topology')


int_inp = lambda : int(input())
strng = lambda : input().strip()
strl = lambda : list(input().strip())
mul = lambda : map(int, input().split())
mulf = lambda : map(float, input().split())
seq = lambda : list(map(int, input().split()))
import math
from collections import Counter, defaultdict
(n, m) = map(int, input().split())
l = [0] * n
for i in range(m):
	(x, y) = map(int, input().split())
	l[x - 1] += 1
	l[y - 1] += 1
l.sort()
if [1] * 2 + [2] * (n - 2) == l:
	print('bus topology')
elif [2] * n == l:
	print('ring topology')
elif [1] * (n - 1) + [n - 1] == l:
	print('star topology')
else:
	print('unknown topology')


from functools import reduce

def add(a, b):
	return a + b
(n, m) = [int(x) for x in input().split()]
neigh = [[] for x in range(n)]
for i in range(m):
	(x, y) = [int(a) for a in input().split()]
	neigh[x - 1].append(y)
	neigh[y - 1].append(x)
(oneneigh, twoneigh, nneigh) = (0, 0, 0)
for i in neigh:
	if len(i) == 1:
		oneneigh += 1
	elif len(i) == 2:
		twoneigh += 1
	else:
		nneigh += 1
if twoneigh == n:
	print('ring topology')
elif oneneigh == 2 and twoneigh == n - 2:
	print('bus topology')
elif nneigh == 1 and oneneigh == m:
	print('star topology')
else:
	print('unknown topology')


from collections import deque
(n, m) = [int(x) for x in input().split()]
(a, c) = ({}, deque([]))
for i in range(1, n + 1):
	a[i] = []
for i in range(m):
	(x, y) = [int(x) for x in input().split()]
	a[x].append(y)
	a[y].append(x)
for k in a.keys():
	c.append(len(a[k]))
if c.count(1) == 2 and c.count(2) == n - 2:
	print('bus topology')
elif c.count(2) == n:
	print('ring topology')
elif c.count(m) == 1 and c.count(1) == m:
	print('star topology')
else:
	print('unknown topology')


def star(graph, n, m):
	if m != n - 1:
		return False
	for k in graph:
		if k == n - 1:
			return True
	return False

def bus(graph):
	c = 2
	for k in graph:
		if k == 1:
			c -= 1
		elif k != 2:
			return False
	return c == 0

def ring(graph):
	for k in graph:
		if k != 2:
			return False
	return True

def solve(graph, n, m):
	if bus(graph):
		return 'bus topology'
	if star(graph, n, m):
		return 'star topology'
	if ring(graph):
		return 'ring topology'
	return 'unknown topology'
(n, m) = map(int, input().split())
graph = [0] * n
for _ in range(m):
	(u, v) = map(lambda x: int(x) - 1, input().split())
	graph[u] += 1
	graph[v] += 1
print(solve(graph, n, m))


def connected(n, adj):
	vis = [False for u in range(n + 1)]
	frontier = [1]
	vis[1] = True
	ptr = 0
	while ptr < len(frontier):
		u = frontier[ptr]
		ptr += 1
		for v in adj[u]:
			if not vis[v]:
				vis[v] = True
				frontier.append(v)
	return all(vis[1:])

def count_degree(n, adj, k):
	return sum((1 for u in range(1, n + 1) if len(adj[u]) == k))

def is_star(n, adj):
	return count_degree(n, adj, 1) == n - 1 and count_degree(n, adj, n - 1) == 1

def is_bus(n, adj):
	return connected(n, adj) and count_degree(n, adj, 2) == n - 2 and (count_degree(n, adj, 1) == 2)

def is_ring(n, adj):
	return connected(n, adj) and count_degree(n, adj, 2) == n

def main():
	(n, m) = map(int, input().split())
	adj = [[] for u in range(n + 1)]
	for _ in range(m):
		(u, v) = map(int, input().split())
		adj[u].append(v)
		adj[v].append(u)
	if is_ring(n, adj):
		print('ring topology')
	elif is_bus(n, adj):
		print('bus topology')
	elif is_star(n, adj):
		print('star topology')
	else:
		print('unknown topology')
main()


I = lambda : map(int, input().split())
(v, e) = I()
D = [0] * (v + 1)
if not (e == v or e == v - 1):
	print('unknown topology')
else:
	for _ in range(e):
		for x in I():
			D[x] += 1
	(a, b, c) = (0, 0, 0)
	for degree in D[1:]:
		if degree == 1:
			a += 1
		elif degree == 2:
			b += 1
		elif degree == v - 1:
			c += 1
	if a == 2 and b == v - 2 and (c == 0) and (e == v - 1):
		print('bus topology')
	elif a == 0 and b == v and (c == 0) and (e == v):
		print('ring topology')
	elif a == v - 1 and b == 0 and (c == 1) and (e == v - 1):
		print('star topology')
	else:
		print('unknown topology')


import re
import itertools
from collections import Counter, deque

class Task:
	(n, m) = (0, 0)
	graph = []
	answer = ''

	def getData(self):
		(self.n, self.m) = [int(x) for x in input().split(' ')]
		for i in range(0, self.m):
			self.graph += [[int(x) for x in input().split(' ')]]

	def solve(self):
		graph = self.graph
		vertexDegrees = [0] * (self.n + 1)
		for edge in graph:
			vertexDegrees[edge[0]] += 1
			vertexDegrees[edge[1]] += 1
		vertexDegrees = vertexDegrees[1:]
		if vertexDegrees.count(2) == len(vertexDegrees):
			self.answer = 'ring topology'
			return
		if vertexDegrees.count(1) == 2 and vertexDegrees.count(2) == len(vertexDegrees) - 2:
			self.answer = 'bus topology'
			return
		if vertexDegrees.count(1) == len(vertexDegrees) - 1:
			self.answer = 'star topology'
			return
		self.answer = 'unknown topology'

	def printAnswer(self):
		print(re.sub('[\\[\\],]', '', str(self.answer)))
task = Task()
task.getData()
task.solve()
task.printAnswer()


(n, m) = map(int, input().split())
from collections import defaultdict
ax = defaultdict(list)
for i in range(m):
	(a, b) = map(int, input().split())
	ax[a].append(b)
	ax[b].append(a)
lend = dict()
for i in range(1, n + 1):
	j = len(ax[i])
	try:
		lend[j] += 1
	except KeyError:
		lend[j] = 1
if lend.get(2, 0) == n:
	print('ring topology')
elif lend.get(1, 0) == 2 and lend.get(2, 0) == n - 2:
	print('bus topology')
elif lend.get(1, 0) == n - 1 and lend.get(n - 1, 0) == 1:
	print('star topology')
else:
	print('unknown topology')


(n, m) = [int(a) for a in input().split()]
list = [None] + [[] for num in range(1, n + 1)]
for roads in range(m):
	(x, y) = [int(i) for i in input().split()]
	list[x].append(y)
	list[y].append(x)
count = [0 for num in range(n)]
for index in range(1, n + 1):
	count[len(list[index])] += 1
if count[1] == 2 and count[2] == n - 2:
	ans = 'bus'
elif count[2] == n:
	ans = 'ring'
elif count[1] == n - 1 and count[n - 1] == 1:
	ans = 'star'
else:
	ans = 'unknown'
print(ans, 'topology')


class CodeforcesTask292BSolution:

	def __init__(self):
		self.result = ''
		self.n_m = []
		self.connections = []

	def read_input(self):
		self.n_m = [int(x) for x in input().split(' ')]
		for x in range(self.n_m[1]):
			self.connections.append([int(y) for y in input().split(' ')])

	def process_task(self):
		graph = [set() for x in range(self.n_m[0])]
		for conn in self.connections:
			graph[conn[0] - 1].add(conn[1])
			graph[conn[1] - 1].add(conn[0])
		conn_cnt = [len(a) for a in graph]
		if conn_cnt.count(1) == 2 and conn_cnt.count(2) == self.n_m[0] - 2:
			self.result = 'bus topology'
		elif conn_cnt.count(1) == self.n_m[0] - 1 and conn_cnt.count(self.n_m[0] - 1) == 1:
			self.result = 'star topology'
		elif conn_cnt.count(2) == self.n_m[0]:
			self.result = 'ring topology'
		else:
			self.result = 'unknown topology'

	def get_result(self):
		return self.result
Solution = CodeforcesTask292BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


(n, m) = map(int, input().split())
counter = [0] * n
for i in range(m):
	(x, y) = map(int, input().split())
	counter[x - 1] += 1
	counter[y - 1] += 1
flag = 0
c1 = c2 = 0
for i in range(n):
	if counter[i] == 1:
		c1 += 1
	elif counter[i] == 2:
		c2 += 1
if c1 == 2 and c2 == n - 2:
	print('bus topology')
else:
	flag += 1
if flag > 0:
	c2 = 0
	for i in range(n):
		if counter[i] == 2:
			c2 += 1
	if c2 == n:
		print('ring topology')
	else:
		flag += 1
if flag > 1:
	c1 = cnm1 = 0
	for i in range(n):
		if counter[i] == 1:
			c1 += 1
		if counter[i] == n - 1:
			cnm1 += 1
	if c1 == n - 1 and cnm1 == 1:
		print('star topology')
	else:
		print('unknown topology')


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
(n, m) = f()
l = [0] * n
for _ in range(m):
	(a, b) = f()
	l[a - 1] += 1
	l[b - 1] += 1
l.sort()
if l[0] == 1 and l[1] == 1 and all((i == 2 for i in l[2:])):
	print('bus topology')
elif all((i == 2 for i in l)):
	print('ring topology')
elif all((i == 1 for i in l[:n - 1])) and l[-1] == n - 1:
	print('star topology')
else:
	print('unknown topology')


from sys import stdin
(node, edge) = map(int, input().split())
capt = [0] * node
for l in stdin.readlines():
	(a, b) = map(int, l.split())
	capt[a - 1] += 1
	capt[b - 1] += 1
(ones, twos) = (capt.count(1), capt.count(2))
if ones == node - 1:
	print('star topology')
elif twos == node:
	print('ring topology')
elif ones == 2 and twos == node - 2:
	print('bus topology')
else:
	print('unknown topology')


from collections import defaultdict
(n, m) = map(int, input().split())
h = defaultdict(set)
nums = [0] * n
for i in range(m):
	(u, v) = map(int, input().split())
	h[u].add(v)
	h[v].add(u)
full = 0
one = 0
two = 0
for (key, value) in h.items():
	if len(value) == n - 1:
		full += 1
	if len(value) == 1:
		one += 1
	if len(value) == 2:
		two += 1
if full == 1 and full + one == n:
	print('star topology')
elif two == n:
	print('ring topology')
elif two == n - 2 and one == 2:
	print('bus topology')
else:
	print('unknown topology')


bt = 'bus topology'
st = 'star topology'
rt = 'ring topology'
ut = 'unknown topology'

def main():
	(n, m) = map(int, input().split())
	S = [0 for j in range(n)]
	for _ in range(m):
		(x, y) = map(int, input().split())
		S[x - 1] += 1
		S[y - 1] += 1
	if S.count(2) == len(S):
		print(rt)
		return
	elif S.count(2) == len(S) - 2 and S.count(1) == 2:
		print(bt)
		return
	elif S.count(n - 1) == 1 and S.count(1) == len(S) - 1:
		print(st)
		return
	else:
		print(ut)
		return
main()


(n, m) = map(int, input().split())
adj = [[] for i in range(n)]
oneDeg = 0
twoDeg = 0
maxDeg = 0
for i in range(m):
	(u, v) = map(int, input().split())
	u -= 1
	v -= 1
	adj[u].append(v)
	adj[v].append(u)
for i in range(n):
	maxDeg = max(maxDeg, len(adj[i]))
	if len(adj[i]) == 1:
		oneDeg += 1
	if len(adj[i]) == 2:
		twoDeg += 1
if oneDeg == n - 1:
	print('star topology')
elif twoDeg == n:
	print('ring topology')
elif oneDeg == 2 and twoDeg == n - 2:
	print('bus topology')
else:
	print('unknown topology')


(n, m) = map(int, input().split())
coords = []
for i in range(m):
	coords.append(list(map(int, input().split())))
if n == m:
	temp = [0] * n
	for i in range(n):
		temp[coords[i][0] - 1] += 1
		temp[coords[i][1] - 1] += 1
	if temp.count(2) == len(temp):
		print('ring topology')
	else:
		print('unknown topology')
else:
	temp = [0] * n
	for i in range(m):
		temp[coords[i][0] - 1] += 1
		temp[coords[i][1] - 1] += 1
	temp2 = set(coords[0])
	for i in range(1, m):
		temp2 &= set(coords[i])
	if len(temp2) > 0:
		print('star topology')
	elif temp.count(1) == 2 and temp.count(2) == len(temp) - 2:
		print('bus topology')
	else:
		print('unknown topology')


(n, m) = map(int, input().split())
db = [[0] for i in range(n)]
for i in range(m):
	(x, y) = map(int, input().split())
	db[x - 1].append(y)
	db[y - 1].append(x)
	db[x - 1][0] += 1
	db[y - 1][0] += 1
one = 0
two = 0
mx = 0
for i in range(n):
	if db[i][0] == 1:
		one += 1
	elif db[i][0] == 2:
		two += 1
	mx = max(mx, db[i][0])
if one == 2 and two == n - 2:
	print('bus topology')
elif two == n:
	print('ring topology')
elif one == n - 1 and mx == n - 1:
	print('star topology')
else:
	print('unknown topology')


N = 100000.0 + 5
M = 100000.0 + 5
(n, m) = map(int, input().split(' '))
d = []
for i in range(0, n + 1):
	d.append(0)
for i in range(0, m):
	(u, v) = map(int, input().split(' '))
	d[u] += 1
	d[v] += 1
flag1 = 1
flag2 = 1
flag3 = 1
d1 = 0
d2 = 0
star_cent = 0
for i in range(1, n + 1):
	if d[i] == 1:
		d1 += 1
	if d[i] == 2:
		d2 += 1
	else:
		flag2 = 0
	if d[i] == n - 1:
		star_cent += 1
if d1 == 2 and d2 == n - 2:
	print('bus topology')
elif flag2:
	print('ring topology')
elif star_cent == 1 and d1 == n - 1:
	print('star topology')
else:
	print('unknown topology')


import sys
from collections import defaultdict

def bus(graph):
	x = None
	y = None
	for (k, v) in graph.items():
		if len(v) == 1:
			x = k
			y = v[0]
			break
	while y in graph:
		if len(graph[y]) == 1:
			if graph[y][0] == x:
				return True
			else:
				return False
		else:
			(a, b) = graph[y]
			if a == x:
				x = y
				y = b
			else:
				x = y
				y = a
	return False

def ring(graph):
	k = next(iter(graph))
	v = graph[k]
	if len(v) != 2:
		return False
	else:
		(x, y) = v
		while y in graph:
			temp = y
			(a, b) = graph[y]
			if a == x:
				x = y
				y = b
			else:
				x = y
				y = a
			del graph[temp]
		if len(graph) == 0:
			return True
		else:
			return False

def star(graph):
	count = 0
	for (k, v) in graph.items():
		if len(v) != 1:
			for i in v:
				if i in graph and len(graph[i]) == 1 and (graph[i][0] == k):
					count += 1
	if len(graph) == count + 1:
		return True
	else:
		return False
(n, m) = list(map(int, sys.stdin.readline().split()))
graph = defaultdict(list)
for i in range(0, m):
	(x, y) = list(map(int, sys.stdin.readline().split()))
	graph[x].append(y)
	graph[y].append(x)
failure = True
try:
	if star(graph):
		print('star topology')
		failure = False
except:
	pass
if failure:
	try:
		if bus(graph):
			print('bus topology')
			failure = False
	except:
		pass
if failure:
	try:
		if ring(graph):
			print('ring topology')
			failure = False
	except:
		pass
if failure:
	print('unknown topology')


(v, e) = list(map(int, input().split()))
graph = {}
for i in range(1, v + 1):
	graph[i] = []
for i in range(e):
	(n1, n2) = list(map(int, input().split()))
	graph[n1].append(n2)
	graph[n2].append(n1)
onedegree = 0
twodegree = 0
gtrtwodegree = 0
for (key, value) in graph.items():
	if len(value) == 1:
		onedegree += 1
	if len(value) == 2:
		twodegree += 1
	if len(value) > 2:
		gtrtwodegree += 1
if onedegree == 2 and v - 2 == twodegree:
	print('bus topology')
elif twodegree == v:
	print('ring topology')
elif gtrtwodegree == 1 and onedegree > 2 and (twodegree == 0):
	print('star topology')
else:
	print('unknown topology')


(n, m) = map(int, input().split())
d = {}
for i in range(1, n + 1):
	d[i] = []
for i in range(m):
	(a, b) = map(int, input().split())
	d[a].append(b)
	d[b].append(a)
sh1 = 0
kol = 0
zvez = 0
for i in d:
	d[i] = len(d[i])
	if d[i] == 0:
		print('unknown topology')
		exit()
	if d[i] > 2:
		sh1 = 3
		kol = 2
		zvez += 1
	elif d[i] == 2:
		zvez += 1
	else:
		sh1 += 1
		kol = 2
if sh1 == 2:
	print('bus topology')
elif kol == 0:
	print('ring topology')
elif zvez == 1:
	print('star topology')
else:
	print('unknown topology')


import sys
from collections import defaultdict
mod = 1000000007

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline()

def print_array(a):
	print(' '.join(map(str, a)))

class Graph:

	def __init__(self):
		self.graph = defaultdict(list)

	def addWire(self, u, v):
		self.graph[u].append(v)
		self.graph[v].append(u)

	def topology(self, n):
		conn = []
		for i in range(1, n + 1):
			conn.append(len(self.graph[i]))
		conn = list(set(conn))
		if len(conn) == 1 and conn[0] == 2:
			return 'ring topology'
		if len(conn) == 2:
			if conn[0] == 1 and conn[1] == n - 1:
				return 'star topology'
			if conn[0] == 1 and conn[1] == 2:
				return 'bus topology'
		return 'unknown topology'

def main():
	(n, m) = get_ints()
	Network = Graph()
	for _ in range(m):
		(x, y) = get_ints()
		Network.addWire(x, y)
	print(Network.topology(n))
main()


import math
import sys
from collections import defaultdict
from collections import Counter
from collections import deque
import bisect
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]
INF = 10 ** 18
MOD = 10 ** 9 + 7
(n, m) = ilele()
A = []
G = defaultdict(list)
D = []
for i in range(m):
	(a, b) = ilele()
	G[a].append(b)
	G[b].append(a)
	D.append(a)
	D.append(b)
	A.append((a, b))
C = Counter(D)
g = C.most_common(1)[0][1]
if g == m:
	print('star topology')
else:
	f = 0
	c = 0
	for (i, j) in G.items():
		if len(j) > 2:
			f = 1
			break
		elif len(j) == 1:
			c += 1
	if f == 1:
		print('unknown topology')
	elif c == 2:
		print('bus topology')
	elif c == 0:
		print('ring topology')
	else:
		print('unknown topology')


import sys
import math
(n, m) = map(int, input().split())
degree = [0] * (n + 1)
for _ in range(0, int(m)):
	(a, b) = map(int, input().split())
	degree[a] = degree[a] + 1
	degree[b] = degree[b] + 1
if degree.count(1) == 2 and degree.count(2) == n - 2:
	print('bus topology')
elif degree.count(2) == n:
	print('ring topology')
elif degree.count(1) == n - 1 and degree.count(n - 1) == 1:
	print('star topology')
else:
	print('unknown topology')


(n, m) = [int(i) for i in input().split()]
s = []
for i in range(n + 1):
	s.append([])
for i in range(m):
	(x, y) = [int(i) for i in input().split()]
	s[x].append(y)
	s[y].append(x)
sbool = [False] * (n + 1)
v2 = 0
v1 = 0
other = 0

def dfs(new):
	global sbool, s, v2, v1, other
	sbool[new] = True
	if len(s[new]) == 1:
		v1 += 1
	elif len(s[new]) == 2:
		v2 += 1
	else:
		other += 1
for i in range(1, n + 1):
	dfs(i)
if v1 == 2 and v2 == n - 2:
	print('bus topology')
elif v1 == n - 1 and other == 1:
	print('star topology')
elif v2 == n:
	print('ring topology')
else:
	print('unknown topology')


from collections import Counter
(n, m) = map(int, input().split())
graph = [[] for _ in range(n)]
for _ in range(m):
	(a, b) = map(int, input().split())
	graph[a - 1].append(b - 1)
	graph[b - 1].append(a - 1)
cnt = dict(Counter(map(len, graph)))
if cnt == {2: n}:
	print('ring topology')
elif cnt == {2: n - 2, 1: 2}:
	print('bus topology')
elif cnt == {1: n - 1, n - 1: 1}:
	print('star topology')
else:
	print('unknown topology')


(n, m) = [int(i) for i in input().split()]
degrees = [0] * n
for i in range(m):
	(x, y) = [int(i) for i in input().split()]
	degrees[x - 1] += 1
	degrees[y - 1] += 1
ones = degrees.count(1)
twos = degrees.count(2)
like_stars = degrees.count(n - 1)
if ones == 2 and twos == n - 2:
	print('bus topology')
elif twos == n:
	print('ring topology')
elif like_stars == 1 and ones == n - 1:
	print('star topology')
else:
	print('unknown topology')


(n, m) = map(int, input().split())
if n > m + 1 or n < m:
	print('unknown topology')
	exit()
array = []
for i in range(m):
	(a, b) = map(int, input().split())
	array.append([a, b])
list_of_edges = [[] for _ in range(n)]
for pair in array:
	(a, b) = map(int, pair)
	list_of_edges[a - 1].append([a, b])
	list_of_edges[b - 1].append([b, a])
if n == m:

	def traverse(list_of_edges, node, prev):
		if len(list_of_edges[node - 1]) != 2:
			print('unknown topology')
			exit()
		for pair in list_of_edges[node - 1]:
			if pair != [node, prev]:
				return [pair[1], pair[0]]
	num = [1, -1]
	for index in range(n):
		num = traverse(list_of_edges, num[0], num[1])
		if num[0] == 1 and index != n - 1:
			print('unknown topology')
			exit()
	if num[0] == 1:
		print('ring topology')
		exit()
	else:
		print('unknown topology')
		exit()
else:
	leaf = 0
	is_star = True
	for i in list_of_edges:
		if len(i) not in [1, n - 1]:
			is_star = False
		if len(i) == 1:
			leaf = i[0]
			leaf.reverse()
	if is_star:
		print('star topology')
		exit()

	def line_traverse(list_of_edges, node, prev):
		if len(list_of_edges[node - 1]) not in [1, 2]:
			print('unknown topology')
			exit()
		for pair in list_of_edges[node - 1]:
			if pair != [node, prev]:
				return [pair[1], pair[0]]
	num = leaf
	for index in range(n - 2):
		num = line_traverse(list_of_edges, num[0], num[1])
		if num[0] == leaf[1]:
			print('unknown topology')
			exit()
	print('bus topology')


R = lambda : map(int, input().split())
(n, m) = R()
c = [0] * n
for i in range(m):
	(x, y) = R()
	c[x - 1] += 1
	c[y - 1] += 1
c1 = c2 = 0
for i in range(n):
	if c[i] == 1:
		c1 += 1
	elif c[i] == 2:
		c2 += 1
if c2 == n:
	print('ring topology')
elif c1 == 2 and c2 == n - 2:
	print('bus topology')
elif c1 == n - 1:
	print('star topology')
else:
	print('unknown topology')


def main():
	(n, m) = [int(x) for x in input().split()]
	computers = {}
	for i in range(m):
		(x, y) = [int(x) for x in input().split()]
		if x not in computers:
			computers[x] = [y]
		else:
			computers[x].append(y)
		if y not in computers:
			computers[y] = [x]
		else:
			computers[y].append(x)
	if m == n:
		for i in computers:
			if len(computers[i]) != 2:
				print('unknown topology')
				return
		print('ring topology')
		return
	elif m == n - 1:
		ones = 0
		for i in computers:
			if len(computers[i]) == 1:
				ones += 1
			if ones > 2:
				break
		if ones == 2:
			print('bus topology')
			return
		else:
			for i in computers:
				if len(computers[i]) != 1:
					if len(computers[i]) == m:
						continue
					else:
						print('unknown topology')
						return
			print('star topology')
	else:
		print('unknown topology')
main()


3
(n, m) = [int(x) for x in input().split()]
degree = {0: 0, 1: 0, 2: 0, n - 1: 0}
visited = [0] * n
adjlist = [[] for x in range(n)]
for i in range(m):
	(x, y) = [int(x) for x in input().split()]
	x -= 1
	y -= 1
	adjlist[x].append(y)
	adjlist[y].append(x)
for i in range(n):
	cur_degree = len(adjlist[i])
	if cur_degree not in degree:
		degree[cur_degree] = 1
	else:
		degree[cur_degree] += 1
degree_other = False
for val in list(degree.keys()):
	if val != 1 and val != 2 and (val != n - 1) and (val != 0):
		degree_other = True
if degree_other == True:
	print('unknown topology')
elif degree[1] == n - 1 and degree[n - 1] == 1:
	print('star topology')
elif degree[1] == 2 and degree[2] == n - 2:
	print('bus topology')
elif degree[2] == n:
	print('ring topology')
else:
	print('unknown topology')


(n, m) = [int(k) for k in input().split()]
ans = 'bus topology'
dict = {}
count = 0
t = 0
if m >= n - 1:
	for i in range(m):
		(first, second) = [int(k) for k in input().split()]
		if first not in dict:
			dict[first] = set()
			dict[first].add(second)
		else:
			if len(dict[first]) == 1:
				count += 1
			else:
				t += 1
			dict[first].add(second)
		if second not in dict:
			dict[second] = set()
			dict[second].add(first)
		else:
			if len(dict[second]) == 1:
				count += 1
			else:
				t += 1
			dict[second].add(first)
if count == n - 2 and m == n - 1:
	print('bus topology')
elif count == 1:
	print('star topology')
elif count == n and t == 0:
	print('ring topology')
else:
	print('unknown topology')


import sys, os.path
from collections import *
from copy import *
import math
mod = 10 ** 9 + 7
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
adj = defaultdict()
(n, m) = map(int, input().split())
for i in range(m):
	(x, y) = map(int, input().split())
	if x not in adj:
		adj[x] = 1
	else:
		adj[x] += 1
	if y not in adj:
		adj[y] = 1
	else:
		adj[y] += 1
c1 = 0
c2 = 0
cn = 0
for i in adj:
	if adj[i] == 1:
		c1 += 1
	elif adj[i] == 2:
		c2 += 1
	elif adj[i] == n - 1:
		cn += 1
if c1 == 2 and c2 == n - 2:
	print('bus topology')
elif c2 == n:
	print('ring topology')
elif cn == 1 and c1 == n - 1:
	print('star topology')
else:
	print('unknown topology')


(n, m) = map(int, input().split())
g = [[] for i in range(n)]
for i in range(m):
	(x, y) = map(int, input().split())
	x -= 1
	y -= 1
	g[x].append(y)
	g[y].append(x)
g = [len(g[i]) for i in range(n)]
if g.count(2) == n - 2 and g.count(1) == 2:
	print('bus topology')
elif g.count(2) == n:
	print('ring topology')
elif g.count(1) == n - 1 and g.count(n - 1) == 1:
	print('star topology')
else:
	print('unknown topology')


from collections import defaultdict
(n, m) = map(int, input().split())
g = defaultdict(int)
for i in range(m):
	(a, b) = map(int, input().split())
	g[a] += 1
	g[b] += 1
cnt1 = cnt2 = 0
for i in g:
	if g[i] == 1:
		cnt1 += 1
	elif g[i] == 2:
		cnt2 += 1
if cnt2 == n:
	print('ring topology')
elif cnt1 == n - 1:
	print('star topology')
elif cnt1 == 2 and cnt2 == n - 2:
	print('bus topology')
else:
	print('unknown topology')


(n, m) = map(int, input().split())
vs = [0 for i in range(n)]
for i in range(m):
	(x, y) = map(int, input().split())
	vs[x - 1] = vs[x - 1] + 1
	vs[y - 1] = vs[y - 1] + 1
if max(vs) == m and n == m + 1:
	print('star topology')
else:
	ones = sum(map(lambda x: 1 if x == 1 else 0, vs))
	if n == m + 1 and ones == 2:
		print('bus topology')
	else:
		doubles = sum(map(lambda x: 1 if x == 2 else 0, vs))
		if n == m and doubles == n:
			print('ring topology')
		else:
			print('unknown topology')


def solve():
	(n, m) = map(int, input().split())
	if n not in (m, m + 1):
		return 3
	l = [0] * (n + 1)
	for _ in range(m):
		(x, y) = map(int, input().split())
		l[x] += 1
		l[y] += 1
	c2 = l.count(2)
	if m == n == c2:
		return 1
	if m == n - 1:
		c1 = l.count(1)
		if c1 == 2 and c2 == n - 2:
			return 0
		if c1 == m and m in l:
			return 2
	return 3

def main():
	print(('bus', 'ring', 'star', 'unknown')[solve()], 'topology')
main()


def buscheck(array, z):
	if amount.count(1) == 2 and amount.count(2) == m - 2:
		return 1
	return 0

def ringcheck(array, z):
	if amount.count(2) == m:
		return 1
	return 0

def starcheck(array, z):
	if amount.count(1) == m - 1 and amount.count(m - 1) == 1:
		return 1
	return 0
(m, n) = [int(x) for x in input().split()]
connect = [[] for i in range(m + 1)]
for i in range(n):
	(a, b) = [int(x) for x in input().split()]
	connect[a].append(b)
	connect[b].append(a)
amount = []
for i in range(1, m + 1):
	amount.append(len(connect[i]))
if starcheck(connect, n):
	print('star topology')
elif ringcheck(connect, n):
	print('ring topology')
elif buscheck(connect, n):
	print('bus topology')
else:
	print('unknown topology')


(n, m) = map(int, input().split())
g = [0 for _ in range(n)]
for _ in range(m):
	(x, y) = map(int, input().split())
	g[x - 1] += 1
	g[y - 1] += 1
if m == n and max(g) == min(g) == 2:
	print('ring topology')
elif m == n - 1 and max(g) < 3:
	print('bus topology')
elif m == n - 1 and max(g) == n - 1:
	print('star topology')
else:
	print('unknown topology')


(n, m) = map(int, input().split())
d = dict()
maxi = 0
maxv = 0
for _ in range(m):
	(a, b) = map(int, input().split())
	if a - 1 in d:
		d[a - 1] += 1
	else:
		d[a - 1] = 1
	if b - 1 in d:
		d[b - 1] += 1
	else:
		d[b - 1] = 1
	if d[a - 1] > maxv:
		maxv = d[a - 1]
		maxi = a - 1
	if d[b - 1] > maxv:
		maxv = d[b - 1]
		maxi = b - 1
if m + 1 == n:
	if maxv == m:
		print('star topology')
	elif maxv == 2:
		print('bus topology')
	else:
		print('unknown topology')
elif m == n:
	if maxv == 2:
		print('ring topology')
	else:
		print('unknown topology')
else:
	print('unknown topology')


(n, m) = map(int, input().split())
adj = dict()
for i in range(m):
	(u, v) = map(int, input().split())
	if u not in adj:
		adj[u] = set()
	if v not in adj:
		adj[v] = set()
	adj[u].add(v)
	adj[v].add(u)
mark = [0] * (n + 1)
mark[0] = 1
start = 1
topology = 'unknown'
one = 0
two = 0
em = 0
oth = 0
for (k, v) in adj.items():
	if len(v) == 1:
		one += 1
	elif len(v) == 2:
		two += 1
	elif len(v) == m:
		em += 1
	else:
		oth += 1
if one == 2 and two == n - 2:
	topology = 'bus'
elif two == n:
	topology = 'ring'
elif em == 1 and n - 1 == one:
	topology = 'star'
print(topology + ' topology')


from collections import defaultdict

def check_bus(g, n):
	v0 = None
	e0 = None
	for (v, elist) in g.items():
		if len(elist) == 1:
			v0 = v
			e0 = elist[0]
			n -= 1
			break
	else:
		return False
	vpred = v0
	v = e0
	while len(g[v]) == 2:
		for e in g[v]:
			if e != vpred:
				vpred = v
				v = e
				break
		n -= 1
	if n != 1:
		return False
	return len(g[v]) == 1

def check_ring(g, n):
	v0 = list(g.keys())[0]
	if len(g[v0]) != 2:
		return False
	n -= 1
	e_back = g[v0][0]
	vpred = v0
	v = g[v0][1]
	while v != v0 and len(g[v]) == 2:
		for e in g[v]:
			if e != vpred:
				vpred = v
				v = e
				break
		n -= 1
		if n < 0:
			return False
	return n == 0

def check_star(g, n):
	v0 = None
	el = None
	for (v, elist) in g.items():
		if len(elist) == n - 1:
			v0 = v
			el = elist
			break
	else:
		return False
	for e in el:
		if len(g[e]) != 1:
			return False
	else:
		return True
(v, e) = [int(x) for x in input().split()]
gd = defaultdict(list)
vset = set()
for _ in range(e):
	(v1, v2) = [int(x) for x in input().split()]
	gd[v1].append(v2)
	gd[v2].append(v1)
	vset.update((v1, v2))
vnum = len(vset)
if check_bus(gd, vnum):
	print('bus topology')
elif check_ring(gd, vnum):
	print('ring topology')
elif check_star(gd, vnum):
	print('star topology')
else:
	print('unknown topology')


(n, m) = map(int, input().split())
a = [0] * n
for i in range(m):
	(x, y) = map(int, input().split())
	a[x - 1] += 1
	a[y - 1] += 1
count2 = 0
count1 = 0
hi = 0
while 1:
	for i in range(len(a)):
		if a[i] == 1:
			count1 += 1
		elif a[i] == 2:
			count2 += 1
		hi = max(hi, a[i])
	if count1 == 2 and count2 == n - 2:
		print('bus topology')
		break
	if count1 == n - 1 and hi == n - 1:
		print('star topology')
		break
	if count2 == n:
		print('ring topology')
		break
	else:
		print('unknown topology')
		break


(n, m) = map(int, input().split())
a = []
for i in range(0, n + 1):
	a.append([])
for i in range(m):
	(i, j) = map(int, input().split())
	a[i].append(j)
	a[j].append(i)
c = 0
d = 0
f = 0
for el in a:
	if len(el) == 1:
		c += 1
	elif len(el) == 2:
		d += 1
	elif len(el) == n - 1:
		f += 1
if c == 2 and d == n - 2:
	print('bus topology')
elif d == n:
	print('ring topology')
elif f == 1 and c == n - 1:
	print('star topology')
else:
	print('unknown topology')


(n, m) = map(int, input().split())
l = []
for i in range(n):
	l.append(0)
for i in range(m):
	(a, b) = map(int, input().split())
	l[a - 1] += 1
	l[b - 1] += 1
m = list(set(l))
if len(m) == 2 and max(l) == 2 and (min(l) == 1) and (l.count(min(l)) == 2):
	print('bus topology')
elif len(m) == 1 and max(l) == 2:
	print('ring topology')
elif len(m) == 2 and max(l) == n - 1 and (l.count(min(l)) == n - 1) and (min(l) == 1):
	print('star topology')
else:
	print('unknown topology')


(n, m) = map(int, input().split())
graph = dict(zip([i + 1 for i in range(n)], [[] for i in range(n)]))
for _ in range(m):
	(u, v) = map(int, input().split())
	graph[u].append(v)
	graph[v].append(u)
freq = {}
for key in graph:
	if len(graph[key]) in freq:
		freq[len(graph[key])] += 1
	else:
		freq[len(graph[key])] = 1
if len(freq) == 2 and 1 in freq and (2 in freq):
	print('bus topology')
elif len(freq) == 1 and 2 in freq:
	print('ring topology')
elif len(freq) == 2 and 1 in freq and (n - 1 in freq):
	print('star topology')
else:
	print('unknown topology')


I = lambda : map(int, input().split())
(n, m) = I()
a = [0] * n
for i in range(m):
	(x, y) = I()
	a[x - 1] += 1
	a[y - 1] += 1
s = set(a)
o = 'unknown'
if s == {2}:
	o = 'ring'
if s == {1, 2}:
	o = 'bus'
if s == {1, m}:
	o = 'star'
print(o, 'topology')


from array import array
from collections import Counter
(n, m) = list(map(int, input().split()))
a = array('L')
a.extend((0 for i in range(n)))
for i in range(m):
	(x, y) = list(map(int, input().split()))
	a[x - 1] += 1
	a[y - 1] += 1
ca = array('L')
ca.extend((0 for i in range(max(a) + 1)))
for i in a:
	ca[i] += 1

def c(i):
	if i >= len(ca) or i < 0:
		return 0
	else:
		return ca[i]
if c(1) == 2 and c(2) == n - 2:
	print('bus topology')
elif c(2) == n:
	print('ring topology')
elif c(1) == n - 1 and c(n - 1) == 1:
	print('star topology')
else:
	print('unknown topology')


(n, m) = map(int, input().split())
arr = [0] * (n + 1)
for w in range(m):
	(a, b) = map(int, input().split())
	arr[a] += 1
	arr[b] += 1
c1 = 0
c2 = 0
cs = 0
for i in range(1, n + 1):
	if arr[i] == 1:
		c1 += 1
	if arr[i] == 2:
		c2 += 1
	if arr[i] == n - 1:
		cs += 1
if c1 == 2 and c2 == n - 2:
	print('bus topology')
elif c2 == n:
	print('ring topology')
elif c1 == n - 1 and cs == 1:
	print('star topology')
else:
	print('unknown topology')


(n, m) = map(int, input().split())
a = []
for h in range(0, n + 1):
	a.append([])
for i in range(m):
	(k, j) = map(int, input().split())
	a[k].append(j)
	a[j].append(k)
d2 = 0
d1 = 0
d3 = 0
for u in a:
	if len(u) == 1:
		d1 += 1
	if len(u) == 2:
		d2 += 1
	if len(u) == n - 1:
		d3 += 1
if d1 == 2 and d2 == n - 2:
	print('bus topology')
elif d3 == 1 and d1 == n - 1:
	print('star topology')
elif d2 == n:
	print('ring topology')
else:
	print('unknown topology')


(n, m) = map(int, input().split())
adj = [[] for i in range(n + 1)]
for i in range(m):
	(a, b) = map(int, input().split())
	adj[a].append(b)
	adj[b].append(a)
edgeCount = [0]
for i in range(1, n + 1):
	edgeCount.append(len(adj[i]))
edgeCountCount = [0 for i in range(n + 1)]
for i in edgeCount:
	edgeCountCount[i] += 1
if edgeCountCount[1] == 2 and edgeCountCount[2] == n - 2:
	print('bus topology')
elif edgeCountCount[2] == m:
	print('ring topology')
elif edgeCountCount[1] == m and edgeCountCount[m] == 1:
	print('star topology')
else:
	print('unknown topology')


__author__ = 'artyom'
read = lambda : map(int, input().split())
(n, m) = read()
graph = [set() for _ in range(1 + n)]
degrees = [0] * (n + 1)
for __ in range(m):
	(u, v) = read()
	graph[u].add(v)
	graph[v].add(u)
	degrees[u] += 1
	degrees[v] += 1

def dfs(start):
	stack = [(start, None)]
	visited = [0] * (n + 1)
	while stack:
		(v, parent) = stack.pop()
		if degrees[v] > 2:
			return 'star' if all([degrees[u] == 1 for u in graph[v]]) else 'unknown'
		for u in graph[v]:
			if u != parent:
				if visited[u]:
					return 'ring' if u == start else 'unknown'
				stack.append((u, v))
		visited[v] = 1
	return 'bus'
print(dfs(1) + ' topology')


from collections import defaultdict
I = lambda : map(int, input().split())
degrees = defaultdict(int)
(n, m) = I()
for _ in range(m):
	(u, v) = I()
	degrees[u] += 1
	degrees[v] += 1
values = set(degrees.values())
answer = 'unknown'
if values == {2}:
	answer = 'ring'
elif values == {1, 2}:
	answer = 'bus'
elif values == {1, m}:
	answer = 'star'
print(answer, 'topology')


(n, m) = map(int, input().split())
g = {}
for _ in range(m):
	(a, b) = map(int, input().split())
	if a not in g:
		g[a] = set()
	if b not in g:
		g[b] = set()
	g[a].add(b)
	g[b].add(a)
n1 = []
n2 = []
for k in range(1, n + 1):
	if len(g[k]) == 1:
		n1.append(k)
	elif len(g[k]) == 2:
		n2.append(k)
if len(n1) == 2 and len(n2) == n - 2:
	print('bus topology')
	quit()
n1 = []
for k in range(1, n + 1):
	if len(g[k]) == 2:
		n1.append(k)
if len(n1) == n:
	print('ring topology')
	quit()
n1 = []
n2 = []
for k in range(1, n + 1):
	if len(g[k]) == 1:
		n1.append(k)
	else:
		n2.append(k)
if len(n1) == n - 1 and len(g[n2[0]]) == n - 1:
	print('star topology')
	quit()
print('unknown topology')


(n, m) = (int(x) for x in input().split())
cnt = [0] * n
for i in range(m):
	(u, v) = (int(x) for x in input().split())
	cnt[u - 1] += 1
	cnt[v - 1] += 1
if cnt.count(1) == n - 1:
	print('star topology')
elif cnt.count(2) == n:
	print('ring topology')
elif cnt.count(1) == 2 and cnt.count(2) == n - 2:
	print('bus topology')
else:
	print('unknown topology')


(n, m) = map(int, input().split())
v = []

def chek_star(v):
	t = 0
	for i in v:
		if i != 1:
			t += 1
	if t == 1:
		return True
	return False
for i in range(n):
	v.append(0)
for i in range(m):
	(t1, t2) = map(int, input().split())
	v[t1 - 1] += 1
	v[t2 - 1] += 1
if max(v) == 2 and min(v) == 2:
	print('ring topology')
elif set(v) == set([1, 2]):
	print('bus topology')
elif set(v) == set([1, max(v)]) and chek_star(v):
	print('star topology')
else:
	print('unknown topology')


(n, m) = list(map(int, input().split()))
d = dict()
for i in range(m):
	(x, y) = list(map(int, input().split()))
	if x in d:
		d[x].add(y)
	else:
		d[x] = set()
		d[x].add(y)
	if y in d:
		d[y].add(x)
	else:
		d[y] = set()
		d[y].add(x)
x = 0
y = 0
z = 0
for i in d:
	if len(d[i]) == 1:
		x += 1
	elif len(d[i]) == 2:
		y += 1
	elif len(d[i]) == m:
		z += 1
if x == n - 1 and y == 0 and (z == 1):
	print('star topology')
elif x == 2 and y == n - 2 and (z == 0):
	print('bus topology')
elif x == 0 and y == n and (z == 0):
	print('ring topology')
else:
	print('unknown topology')


(n, m) = map(int, input().split())
graph = {i: [] for i in range(1, n + 1)}
for i in range(m):
	(start, end) = map(int, input().split())
	graph[start].append(end)
	graph[end].append(start)
length_array = []
for i in graph:
	length_array.append(len(graph[i]))
if min(length_array) == max(length_array) and max(length_array) == 2:
	print('ring topology')
elif length_array.count(1) == 2 and length_array.count(2) == n - 2:
	print('bus topology')
elif max(length_array) == m and m == n - 1:
	print('star topology')
else:
	print('unknown topology')


(n, m) = map(int, input().split())
l = [0] * n
for i in range(m):
	(x, y) = map(int, input().split())
	l[x - 1] += 1
	l[y - 1] += 1
l.sort()
if [1] * 2 + [2] * (n - 2) == l:
	print('bus topology')
elif [2] * n == l:
	print('ring topology')
elif [1] * (n - 1) + [n - 1] == l:
	print('star topology')
else:
	print('unknown topology')


import sys
from math import ceil, floor, log2, sqrt

def readall():
	return [int(x) for x in sys.stdin.read().split()]

def u():
	return [int(i) for i in sys.stdin.readline().split()]
(n, m) = u()
deg = [0] * (n + 1)
for _ in range(m):
	(a, b) = u()
	deg[a] += 1
	deg[b] += 1
ring = star = bus = True
oneCount = 0
for j in range(1, n + 1):
	if deg[j] != 2:
		ring = False
	if deg[j] > 2:
		bus = False
		if deg[j] != n - 1 or m != n - 1:
			star = False
ans = ''
if ring:
	ans += 'ring'
elif bus:
	ans += 'bus'
elif star:
	ans += 'star'
else:
	ans += 'unknown'
print(ans + ' topology')


from collections import defaultdict, Counter
(N, M) = map(int, input().split())
AdjList = defaultdict(int)
for i in range(M):
	(a, b) = map(int, input().split())
	AdjList[a] += 1
	AdjList[b] += 1
CheckList = []
for i in AdjList.values():
	CheckList.append(i)
Freq = Counter(CheckList)
if len(Freq.values()) == 1 and Freq[2] != 0:
	print('ring topology')
elif len(Freq.values()) == 2 and Freq[1] == 2 and (Freq[2] != 0):
	print('bus topology')
elif len(Freq.values()) == 2 and Freq[1] == N - 1:
	print('star topology')
else:
	print('unknown topology')


import sys
inp = lambda : sys.stdin.readline()
(n, m) = map(int, inp().split())
d = [0] * n
for _ in range(m):
	(x, y) = map(int, inp().split())
	d[x - 1] += 1
	d[y - 1] += 1
maxm = max(d)
minm = min(d)
maxm_count = d.count(maxm)
minm_count = d.count(minm)
if maxm == 2 and maxm_count == n - 2 and (minm == 1) and (minm_count == 2) or (n == 2 and maxm == 1 and (minm == 1)):
	print('bus topology')
elif maxm == minm == 2 and maxm_count == n:
	print('ring topology')
elif maxm == n - 1 and maxm_count == 1 and (minm == 1) and (minm_count == n - 1):
	print('star topology')
else:
	print('unknown topology')


v = input().split()
n = int(v[0])
m = int(v[1])
c = {}
for i in range(n):
	c[i + 1] = 0
for i in range(m):
	b = input().split()
	c[int(b[0])] += 1
	c[int(b[1])] += 1
flag1 = 0
flag2 = 0
for i in c:
	if c[i] == 2:
		flag1 += 1
	if c[i] == m:
		print('star topology')
		exit()
	if c[i] == 1:
		flag2 += 1
if flag1 == n:
	print('ring topology')
elif flag2 == 2 and flag1 == n - 2:
	print('bus topology')
else:
	print('unknown topology')


(n, m) = map(int, input().split())
c = [0 for _ in range(n)]
for _ in range(m):
	(a, b) = map(int, input().split())
	c[a - 1] += 1
	c[b - 1] += 1
s = set(c)
res = 'unknown'
if s == {2}:
	res = 'ring'
elif s == {1, 2}:
	res = 'bus'
elif s == {1, m}:
	res = 'star'
print(res + ' topology')


(n, m) = map(int, input().split())
p = [0] * (n + 1)
for i in range(m):
	(a, b) = map(int, input().split())
	p[a] += 1
	p[b] += 1
ans = 'unknown topology'
if n == m:
	if p.count(2) == n:
		ans = 'ring topology'
elif n == m + 1:
	if n - 1 in p:
		ans = 'star topology'
	elif p.count(1) == 2 and p.count(2) == n - 2:
		ans = 'bus topology'
print(ans)


(n, m) = map(int, input().split())
d = [0] * (n + 1)
for i in range(m):
	(a, b) = map(int, input().split())
	d[a] += 1
	d[b] += 1
count = 0
count2 = 0
count3 = -1
for i in d:
	if i == 1:
		count += 1
	elif i == 2:
		count2 += 1
	else:
		count3 += 1
if count == 0 and count2 == n and (count3 == 0):
	print('ring topology')
elif count == n - 1 and count2 == 0 and (count3 == 1):
	print('star topology')
elif count == 2 and count2 == n - 2 and (count3 == 0):
	print('bus topology')
else:
	print('unknown topology')


from collections import defaultdict
(n, m) = map(int, input().split())
g = defaultdict(list)
for i in range(m):
	(u, v) = map(int, input().split())
	g[u].append(v)
	g[v].append(u)
flag1 = True
for i in g:
	if len(g[i]) != 2:
		flag1 = False
		break
if flag1:
	print('ring topology')
	exit(0)
st1 = set()
for i in g:
	st1.add(len(g[i]))
l = list(st1)
l.sort()
if len(l) == 2 and l[0] == 1 and (l[1] == n - 1):
	print('star topology')
	exit(0)
elif len(l) == 2 and l[0] == 1 and (l[1] == 2):
	print('bus topology')
	exit(0)
else:
	print('unknown topology')
	exit(0)


(x, y) = (0, 0)
countZero = 0
countOne = 0
(n, m) = [int(i) for i in input().split()]
a = [0] * n
for i in range(m):
	(x, y) = [int(i) for i in input().split()]
	a[y - 1] += 1
	a[x - 1] += 1
for i in a:
	if i == 1:
		countZero += 1
	elif i > 1:
		countOne += 1
if n == m:
	if countZero == 0 and countOne == n:
		print('ring topology')
	else:
		print('unknown topology')
elif n - m == 1:
	if countZero == 2 and countOne == n - 2:
		print('bus topology')
	elif countZero == n - 1 and countOne == 1:
		print('star topology')
	else:
		print('unknown topology')
else:
	print('unknown topology')


(n, m) = map(int, input().split())
all_one = True
all_one_except = True
one_except = False
all_two = True
visited = [False] * (n + 1)
st = [0] * (n + 1)
for i in range(m):
	(a, b) = map(int, input().split())
	st[a] += 1
	st[b] += 1
for i in range(1, n + 1):
	if st[i] != 2:
		all_two = False
	if st[i] > 2:
		all_one = False
	if st[i] > 1:
		if one_except:
			all_one_except = False
		else:
			one_except = True
	if not (all_one or all_two or all_one_except):
		break
if all_two:
	print('ring topology')
elif all_one:
	print('bus topology')
elif all_one_except:
	print('star topology')
else:
	print('unknown topology')


(n, m) = map(int, input().split())
graph = {i: [] for i in range(1, n + 1)}
for i in range(m):
	(u, v) = map(int, input().split())
	graph[u].append(v)
	graph[v].append(u)
degree = {i: 0 for i in range(1, n + 1)}
tot_degree = {i: 0 for i in range(1, n + 1)}
for i in range(1, n + 1):
	ln = len(graph[i])
	degree[i] = ln
	tot_degree[ln] += 1
if m == n - 1 and tot_degree[1] == 2 and (tot_degree[2] == n - 2):
	print('bus topology')
elif m == n and tot_degree[2] == n:
	print('ring topology')
elif m == n - 1 and tot_degree[n - 1] == 1 and (tot_degree[1] == n - 1):
	print('star topology')
else:
	print('unknown topology')