QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#703537#6634. Central SubsetlvliangWA 131ms8764kbC++141.4kb2024-11-02 17:56:082024-11-02 17:56:10

Judging History

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

  • [2024-11-02 17:56:10]
  • 评测
  • 测评结果:WA
  • 用时:131ms
  • 内存:8764kb
  • [2024-11-02 17:56:08]
  • 提交

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) {
    int dist = 1;
    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 + 1) {
        ans[tp++] = u;
        dist = 0;
    }
    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);
    if (!tp) 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: 100
Accepted
time: 0ms
memory: 8404kb

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
2 
1
1 

result:

ok correct (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 131ms
memory: 8764kb

input:

10000
15 14
13 12
5 4
9 8
11 12
15 14
10 9
14 13
2 3
2 1
6 5
10 11
3 4
7 6
8 7
6 5
2 1
2 4
4 6
2 3
3 5
10 9
8 3
9 4
5 6
5 10
3 2
5 4
2 7
1 2
4 3
2 1
2 1
2 1
2 1
9 8
9 8
5 4
1 2
6 5
3 4
3 2
7 8
7 6
2 1
1 2
14 13
3 10
5 6
2 9
11 4
2 3
2 1
8 7
13 6
5 4
5 12
6 7
4 3
7 14
16 15
2 3
2 1
6 10
6 9
6 4
9 11
...

output:

3
11 6 1 
1
1 
1
2 
1
1 
1
1 
2
6 2 
1
1 
1
4 
2
10 3 
1
1 
3
15 9 3 
1
3 
1
2 
1
5 
1
1 
3
11 6 1 
1
1 
1
1 
1
2 
1
1 
1
2 
1
3 
1
4 
2
5 1 
1
1 
3
11 6 1 
1
1 
2
5 1 
1
1 
1
1 
3
16 10 4 
1
2 
1
4 
2
7 4 
1
1 
1
3 
1
2 
1
3 
3
6 7 1 
1
1 
2
8 3 
1
1 
1
3 
1
2 
1
1 
2
6 1 
1
3 
1
3 
2
5 1 
1
1 
3
1...

result:

wrong answer Condition failed: "getMaxBfsDist(n, subset) <= csqrtn" (test case 402)