QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#202106 | #6634. Central Subset | arseny_y# | WA | 0ms | 17240kb | C++23 | 1.5kb | 2023-10-05 19:24:59 | 2023-10-05 19:24:59 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
const int MAXN = 2e5 + 10;
vector<int> g[MAXN], tr[MAXN];
int sq = 1;
int usd[MAXN];
void dfs(int v = 1) {
usd[v] = true;
for (auto &to : g[v]) {
if (!usd[to]) {
tr[v].push_back(to);
dfs(to);
}
}
}
int in_ans[MAXN];
int up[MAXN];
void tree_dfs(int v = 1) {
for (auto &to : tr[v]) tree_dfs(to);
up[v] = 0;
for (auto &to : tr[v]) {
if (!in_ans[to]) {
up[v] = max(up[v], up[to] + 1);
}
}
if (up[v] > sq || v == 1) {
in_ans[v] = true;
}
}
int32_t main(){
cin.tie(nullptr)->sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
sq = 1;
while (sq * sq < n) ++sq;
for (int i = 1; i <= n; ++i) g[i].clear(), tr[i].clear(), usd[i] = false, in_ans[i] = false, up[i] = 0;
int m;
cin >> m;
for (int i = 0, x, y; i < m; ++i) {
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
dfs(), tree_dfs();
vector<int> ans;
for (int i = 1; i <= n; ++i) {
if (in_ans[i]) ans.push_back(i);
}
if (ans.size() > sq) {
cout << "-1\n";
continue;
}
cout << ans.size() << '\n';
for (auto &el : ans) cout << el << ' ';
cout << '\n';
}
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 17240kb
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)