我的思路是基于点的度数:
想不到到底是哪里错了?哪些情况没覆盖到?
#include <iostream>
#include <algorithm>
using namespace std;
int a[100005],n,m;
int main() {
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int tx,ty;
cin>>tx>>ty;
a[tx]++;
a[ty]++;
}
sort(a+1,a+n+1);
//for(int i=1;i<=n;i++) cout<<a[i]<<' ';
cout<<endl;
if(n==2&&m==1)
{
cout<<"bus topology";
return 0;
}
if(n==2&&m==2)
{
cout<<"unknown topology";
return 0;
}
if(n==1)
{
cout<<"unknown topology";
return 0;
}
if(a[1]==1&&a[2]==1&&a[3]==2)
{
cout<<"bus topology";
return 0;
}
else if(a[1]==a[n]&&a[n]==2)
{
cout<<"ring topology";
return 0;
}
else if(a[n]==n-1&&a[n-1]==1)
{
cout<<"star topology";
return 0;
}
cout<<"unknown topology";
return 0;
}