QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#226296#6634. Central SubsetxuxubaobaoWA 3ms50792kbC++17852b2023-10-25 19:43:462023-10-25 19:43:47

Judging History

你现在查看的是最新测评结果

  • [2023-10-25 19:43:47]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:50792kb
  • [2023-10-25 19:43:46]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using PII = pair<int,int>;
using ll = long long;

constexpr int N = 2e6 + 10;
vector<int> ans;
vector<int> e[N];
int d[N];
ll k;
void dfs(int u, int cnt) {
	if(cnt % (k + 1) == 0 && cnt != 0) ans.push_back(u);
	d[u] = 1;
	for(auto v : e[u]) {
		if(d[v] == -1) {
			dfs(v, cnt + 1);
		}
	}
}

void solve() {
	int n, m;
	cin >> n >> m;
	k = ceil(sqrt(n));
	ans.clear();
	for(int i = 1; i <= n; i ++) e[i].clear(), d[i] = -1;
	for(int i = 1; i <= m; i ++) {
		int u, v;
		cin >> u >> v;
		e[u].push_back(v);
		e[v].push_back(u);
	}
	dfs(1, 0);
	cout << ans.size() << "\n";
	for(auto v : ans) {
		cout << v << " ";
	}
	cout << "\n";
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	t = 1;
	cin >> t;
	while(t --){
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 50792kb

input:

2
4 3
1 2
2 3
3 4
6 7
1 2
2 3
3 1
1 4
4 5
5 6
6 4

output:

1
4 
0


result:

wrong answer Condition failed: "getMaxBfsDist(n, subset) <= csqrtn" (test case 1)