QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#226296 | #6634. Central Subset | xuxubaobao | WA | 3ms | 50792kb | C++17 | 852b | 2023-10-25 19:43:46 | 2023-10-25 19:43:47 |
Judging History
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)