fork download
  1. //Source: JadArab
  2.  
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5.  
  6. int main() {
  7. int n, m;
  8. cin >> n >> m;
  9. vector<int> deg(n+1, 0);
  10.  
  11. for (int i = 0; i < m; ++i) {
  12. int x, y;
  13. cin >> x >> y;
  14. deg[x]++, deg[y]++;
  15. }
  16.  
  17. int d1 = 0, d2 = 0, dn = 0;
  18. for (int i = 1; i <= n; ++i) {
  19. if (deg[i] == 1) d1++;
  20. else if (deg[i] == 2) d2++;
  21. else if (deg[i] == n-1) dn++;
  22. }
  23.  
  24. if (m == n - 1 && d1 == 2 && d2 == n - 2) cout << "bus topology";
  25. else if (m == n && d2 == n) cout << "ring topology";
  26. else if (m == n - 1 && dn == 1 && d1 == n - 1) cout << "star topology";
  27. else cout << "unknown topology";
  28.  
  29. return 0;
  30. }
Runtime error #stdin #stdout #stderr 0.01s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc