QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#220821 | #6634. Central Subset | real_sigma_team | WA | 0ms | 8292kb | C++20 | 1.5kb | 2023-10-20 21:02:02 | 2023-10-20 21:02:03 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using ll = long long;
const int N = 2e5 + 5;
const int K = 449;
vector<int> gr[N];
int d[N], used[N];
const int inf = 1e9;
int k;
vector<int> ans;
void dfs(int v, int p) {
used[v] = 1;
int mx = -1;
int ch = 0;
for (int u: gr[v]) {
if (used[u] == 0){
dfs(u, v);
ch++;
mx = max(mx, d[u]);
}
}
if (ch == 0) {
d[v] = 0;
}else{
if(v == 0){
if(mx != -1){
ans.push_back(v + 1);
}
}else{
if (mx + 1 >= k) {
ans.push_back(v + 1);
d[v] = -1;
}
}
}
}
void solve() {
int n, m;
cin >> n >> m;
k = ceil(sqrt(n));
{
ans.clear();
for (int i = 0; i < n; i++)
gr[i].clear(), used[i] = 0, d[i] = 0;
}
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
u--, v--;
gr[u].push_back(v);
gr[v].push_back(u);
}
dfs(0,-1);
cout << sz(ans) << '\n';
for (int i: ans) {
cout << i << ' ';
}
cout << '\n';
}
int main() {
#ifndef LOCAL
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#else
freopen("input.txt", "r", stdin);
#endif
int t;
cin >> t;
while (t--)
solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 8292kb
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 1 1 1
result:
wrong answer Condition failed: "getMaxBfsDist(n, subset) <= csqrtn" (test case 1)