关于re错误的问题
  • 板块学术版
  • 楼主534216cc
  • 当前回复1
  • 已保存回复1
  • 发布时间2022/9/24 22:23
  • 上次更新2023/10/27 10:04:15
查看原帖
关于re错误的问题
699457
534216cc楼主2022/9/24 22:23

求大佬帮忙看看哪里错了 P5318第一个检测点过了后面三个re了 谢谢大佬

#include<iostream>
#include<vector>
#include<queue>
#include<algorithm> 
#include<cstring>
using namespace std;
const int N=10005;
const int M=10005;
vector<int>g[N];
bool vit[N];
int n,m;
void dfs(int n)
{
	if(vit[n]==1)
		return ;
	else
	{
		vit[n]=1;
		cout<<n<<" ";
		for(auto e : g[n])
		{
			dfs(e);
		}
	}
	
}
void bfs(int n)
{
	queue<int>q;
	q.push(n);
	
	while(!q.empty())
	{
		int u=q.front();
		q.pop();
		
		if(vit[u]==1)
			continue;
		vit[u]=1;
		cout<<u<<" ";
		for(auto e : g[u])
		{
			q.push(e);
		}
	}
}

int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int v,w;
		cin>>v>>w;
		g[v].push_back(w);
	}//图的存储
	for(int i=1;i<=m;i++)
		sort(g[i].begin(),g[i].end());
	dfs(1);
	cout<<endl;
	memset(vit,0,sizeof(vit));
	bfs(1);
	
}
2022/9/24 22:23
加载中...