求助
查看原帖
求助
470331
lch2021楼主2021/7/20 11:44

为什么我的bfs输出到6就停了?而且调试的时候到第14行的时候会出一个奇怪的问题。。。


#include<bits/stdc++.h>
using namespace std;
int i,j,k,n,m,a,b;
int see[100005];
vector<int> v[100005];
queue<int> q;
void dfs(int x){
	see[x]=1;
	cout<<x<<" ";
	if(!v[x].empty())
	{
		for(i=0;i<v[x].size();i++)
		{
			if(see[v[x][i]]==0)
			{
				dfs(v[x][i]);
			}
		}
	}
	else return;
}
inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}
int main(){
	n=read();
	m=read();
	for(i=1;i<=m;i++)
	{
		a=read();
		b=read();
		v[a].push_back(b);
		
	}
	for(i=1;i<=n;i++)
		sort(v[i].begin(),v[i].end());
	/*cout<<endl;
	for(i=1;i<=n;i++)
	{
		for(j=0;j<v[i].size();j++)
			cout<<v[i][j]<<" ";
		cout<<endl;
	}*/
	dfs(1);
	return 0;
}
2021/7/20 11:44
加载中...