QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#703831#6634. Central SubsetlvliangWA 1ms6752kbC++141.4kb2024-11-02 18:38:152024-11-02 18:38:16

Judging History

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

  • [2024-11-02 18:38:16]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6752kb
  • [2024-11-02 18:38:15]
  • 提交

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)