自己写的垃圾写法,结果 WA 了……
代码
#include<bits/stdc++.h>
using namespace std;
int n,m,dd=-1,k_=-1;
bool flag=1;
vector<int>v[100005];
bool b[100005];
void dfs(int x,int sum){
if(b[x]){
if(sum>m){
cout<<"ring topology";
}else{
cout<<"unknown topology";
}
exit(0);
}
for(auto u:v[x]){
b[x]=1;
dfs(u,sum+1);
}
}
int main(){
ios::sync_with_stdio(0),cin.tie(0),cin.tie(0);
cin>>n>>m;
for(int i=1,l,r;i<=m;i++){
cin>>l>>r;
v[l].push_back(r);
if(dd==-1){
dd=l;
}
if(k_==-1){
k_=l;
}
if(dd!=l){
flag=0;
}
}
if(flag){
cout<<"star topology";
return 0;
}
dfs(k_,1);
cout<<"bus topology";
return 0;
}
hack 数据点
input
5 5
3 4
5 2
2 1
5 4
3 1
output
5 5
3 4
5 2
2 1
5 4
3 1
~~很久没发贴了。~~