QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#703831 | #6634. Central Subset | lvliang | WA | 1ms | 6752kb | C++14 | 1.4kb | 2024-11-02 18:38:15 | 2024-11-02 18:38:16 |
Judging History
answer
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#define x first
#define y second
using namespace std;
const int N = 2e5 + 10;
int h[N], e[N << 1], ne[N << 1], idx;
int ans[N], tp;
int p[N];
void add(int a, int b) {
e[++idx] = b, ne[idx] = h[a], h[a] = idx;
}
int find(int x) {
if (x ^ p[x]) p[x] = find(p[x]);
return p[x];
}
int sqrtn;
int dfs(int u, int fa) {
if (tp == sqrtn) return 0;
int dist = 0;
for (int i = h[u]; i; i = ne[i]) {
int j = e[i];
if (j == fa) continue;
dist = max(dfs(j, u) + 1, dist);
}
if (dist == sqrtn) {
ans[tp++] = u;
dist = -1;
}
return dist;
}
void solve() {
tp = 0;
idx = 0;
memset(h, 0, sizeof h);
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) p[i] = i;
for (int i = 0; i < m; i++) {
int u, v;
scanf("%d%d", &u, &v);
int fu = find(u), fv = find(v);
if (fu ^ fv) {
p[fu] = fv;
add(u, v), add(v, u);
}
}
sqrtn = ceil(sqrt(n));
dfs(1, -1);
ans[tp++] = 1;
printf("%d\n", tp);
for (int i = 0; i < tp; i++) {
printf("%d ", ans[i]);
}
puts("");
}
int main() {
int T;
scanf("%d", &T);
while (T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 6752kb
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:
2 2 1 2 1 1
result:
wrong answer Condition failed: "subset.size() == sz" (test case 2)