样例能过,但全WA
查看原帖
样例能过,但全WA
1067789
Director_Ni楼主2024/11/13 20:57
#include<bits/stdc++.h>
using namespace std;
const int N= 1e5;
bool b[N];
struct node{
    int bh;
    vector<int>z;
    void paixu(){
        sort(z.begin(),z.end());
    }
}a[100000];
void dfs (int root){
    cout<<root<<" ";
    b[root]=1;
    a[root].paixu();
    for(int k:a[root].z){
        if(!b[k]){
            dfs(k);
        }
    }
}
int main(){
    int n,m;
    cin>>n>>m;
    memset(b,'0',sizeof(b));
    int fa,ch;
    for(int i=1;i<=m;++i){
        cin>>fa>>ch;
        a[fa].bh=fa;a[fa].z.push_back(ch);
    }
    dfs(1);
    memset(b,'0',sizeof(b));
    cout<<endl;
    queue<int> qu;
    qu.push(1);
    while(!qu.empty()){
        int t=qu.front();
        qu.pop();
        if(!b[t]){
        cout<<t<<" ";
        b[t]=1;
        a[t].paixu();
        for(int k:a[t].z){
            qu.push(k);
        }
        }
    }
}

各位大佬麻烦帮我看一下,说是第一行太短

2024/11/13 20:57
加载中...