QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#703810#6634. Central SubsetlvliangWA 11ms8036kbC++141.6kb2024-11-02 18:32:532024-11-02 18:32:58

Judging History

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

  • [2024-11-02 18:32:58]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:8036kb
  • [2024-11-02 18:32:53]
  • 提交

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 = 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(int x, bool ht) {
    
    tp = 0;
    idx = 0;
    
    int n, m;
    scanf("%d%d", &n, &m);
    int f = false;
    if (x == 420) f = true;
    if (f) cout << n << " " << m << endl;
    for (int i = 1; i <= n; i++) p[i] = i, h[i] = 0;
    for (int i = 0; i < m; i++) {
        int u, v;
        scanf("%d%d", &u, &v);
        if (f) cout << u << " " << v << endl;
        int fu = find(u), fv = find(v);
        if (fu ^ fv) {
            p[fu] = fv;
            add(u, v), add(v, u);
        }
    }
    if (!ht) return;
    
    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);
    int ht = false;
    if (T == 2) ht = true;
    int i = 0;
    while (T--) {
        i++;
        solve(i, ht);
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 8036kb

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: 11ms
memory: 7852kb

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:

9 8
7 2
2 3
2 9
6 2
2 4
8 2
5 2
2 1

result:

wrong answer Integer 9 violates the range [1, 4] (test case 1)