RE 了求调
查看原帖
RE 了求调
726044
WA_WonderfulAnswer楼主2023/11/30 19:38

为什么全 RE 呢?

我在 DEV-C++ 上没有输入输出就 return 了个 $3321225477$


#include <iostream>
#include <queue>
using namespace std;
const int N = 1e6 + 5;
int gr[N][N];
int used[N];
int n, m;

void dfs(int x) {
	if (used[x])
		return;
	cout << x << ' ';
	used[x] = 1;
	for (int i = 1; i <= n; i++)
		if (gr[x][i] == 1 && !used[i])
			dfs(i);
}

void bfs(int x) {
	queue<int> q;
	q.push(x);
	used[x] = 1;
	while (!q.empty()) {
		int h = q.front();
		q.pop();
		cout << h << " ";
		for (int i = 1; i <= n; i++) {
			int t = gr[h][i];
			if (!used[i]) {
				q.push(i);
				used[i] = 1;
			}
		}
	}
}

int main() {
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		int a, b;
		cin >> a >> b;
		gr[a][b] = 1;
	}
	dfs(1);
	cout << endl;
	for (int i = 1; i <= N; i++)
		used[i] = 0;
	bfs(1);
	return 0;
}
2023/11/30 19:38
加载中...