Wrong answer on test 6 求助!!!
查看原帖
Wrong answer on test 6 求助!!!
1050501
ATION001楼主2024/8/27 10:49

自己写的垃圾写法,结果 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
~~很久没发贴了。~~
2024/8/27 10:49
加载中...