forked from joy-mollick/Problem-Solving-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Codeforces-292B - Network Topology.cpp
101 lines (95 loc) · 1.48 KB
/
Codeforces-292B - Network Topology.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include<bits/stdc++.h>
using namespace std;
const int mx=1e5+1;
bool vis[mx];
vector<int>adj[mx];
int n;
bool star()
{
bool ans;
int count1=0;
int other=0;
for(int i=1;i<=n;i++)
{
if(adj[i].size()==1)
{
count1++;
}
else if(adj[i].size()==n-1)
{
other++;
}
}
if(other==1&&count1==n-1)
{
ans=true;
}
else{
ans=false;
}
return ans;
}
bool ring()
{
bool ans=true;
for(int i=1;i<=n;i++)
{
if(adj[i].size()!=2)
{
ans=false;
break;
}
}
return ans;
}
bool bus()
{
bool ans;
int one=0;
int two=0;
for(int i=1;i<=n;i++)
{
if(adj[i].size()==1)
{
one++;
}
else if(adj[i].size()==2)
{
two++;
}
}
if(one==2 && two==n-2)
{
ans=true;
}
else{
ans=false;
}
return ans;
}
int main()
{
int m,k,u,v;
cin>>n>>m;
for(int i=0;i<m;i++)
{
cin>>u>>v;
adj[u].push_back(v);
adj[v].push_back(u);
}
if(star())
{
cout<<"star topology"<<endl;
}
else if(bus())
{
cout<<"bus topology"<<endl;
}
else if(ring())
{
cout<<"ring topology"<<endl;
}
else{
cout<<"unknown topology"<<endl;
}
}