auto使用错误,大佬救我!!!
查看原帖
auto使用错误,大佬救我!!!
795984
glad_yimie楼主2023/7/20 21:52

直接上代码

#include<bits/stdc++.h>
using namespace std;

set<int> s[100004]/*on*/;//一大堆点的儿子
int n,m;
bool chk[100004];

void dfs(int x)
{
    if(chk[k])
    {
        return ;
    }
    chk[k]=1;
    cout<<x<<" ";
    for(auto i:s[x])dfs(i);
}

void bfs()
{
    queue<int> q;
    q.push(1);
    while(!q.empty())
    {
        int x=q.front();
        q.pop();
        if(chk[x])continue;
        chk[x]=1;
        cout<<x<<" ";
        for(auto i:s[x])q.push(i);
    }
    
}

int main()
{
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        int t,x;
        cin>>t>>x;
        s[t].insert(x);//第t个点的儿子,set已排好
    }
    dfs(1);
    cout<<endl;
    bfs(1);
}
2023/7/20 21:52
加载中...