QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#726441#6634. Central SubsetsyhyydsWA 23ms10960kbC++172.0kb2024-11-09 00:41:362024-11-09 00:41:36

Judging History

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

  • [2024-11-09 00:41:36]
  • 评测
  • 测评结果:WA
  • 用时:23ms
  • 内存:10960kb
  • [2024-11-09 00:41:36]
  • 提交

answer

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <math.h>
#include <map>
#include <sstream>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <array>
#include <climits>
using namespace std;
#define   LL long long
#define ls o<<1
#define rs o<<1|1
#define PII pair<int,int>
#define PPI pair<pair<int,int>,int >
const int N = 2e5 + 1000;
const LL  mod = 998244353;
const LL MAX = 1e18;
vector<int> g[N];
int n, m;
int fa[N], ans[N], cn = 0, d,dep[N],maxx=0;
int father(int x)
{
    if (fa[x] != x)
        fa[x] = father(fa[x]);
    return fa[x];
}
int dfs(int u, int fa)
{   
    dep[u] = dep[fa] + 1;
    maxx = max(maxx, dep[u]);
    int fg = 0,cx=0;
    for (int v : g[u]) 
    {

        if (v == fa) continue;
        cx=max(cx,dfs(v, u)+1);
        fg = 1;
    }
    if (cx == d) 
    {
        ans[++cn] = u;
        return 0;
    }
    if (!fg) return 1;
    return cx;
}
void solve()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) dep[i]=0, fa[i] = i, g[i].clear();
    for (int i = 1; i <= m; i++)
    {
        int u, v;
        scanf("%d%d", &u, &v);
        int fau = father(u), fav = father(v);
        if (fau != fav)
        {
            fa[fau] = fav;
            g[u].push_back(v);
            g[v].push_back(u);  

        }
    }
    d = sqrt(n);
    if (d * d < n) d++;
    dep[1] = -1;
    maxx = 0;
    cn = 0;
    dfs(1, 1);
    if (maxx<d) 
    {
        printf("1\n");
        printf("1\n");
        return  ;
    }
    printf("%d\n", cn);
    for (int i = 1; i <= cn; i++)
        printf("%d ", ans[i]);
    printf("\n");
    return;
}
int main()
{

    int T = 1;
    cin >> T;
    while (T--)
        solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 10960kb

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

result:

ok correct (2 test cases)

Test #2:

score: 0
Accepted
time: 16ms
memory: 10836kb

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
12 8 4 
1
2 
1
3 
1
1
1
1
3
7 4 1 
1
1
2
5 2 
2
12 4 
1
1
4
16 11 6 1 
2
4 2 
1
3 
2
8 2 
1
1
3
12 8 4 
1
2 
1
1
2
4 2 
1
1
2
3 1 
2
4 2 
2
5 2 
2
8 2 
1
1
3
12 8 4 
1
2 
2
6 3 
1
2 
1
1
4
17 12 7 2 
1
3 
2
5 2 
3
10 6 1 
1
1
2
4 1 
1
3 
2
4 1 
3
10 9 2 
1
1
3
9 5 1 
1
2 
2
4 1 
2
3 1 
1
1
2
7 3 
...

result:

ok correct (10000 test cases)

Test #3:

score: -100
Wrong Answer
time: 23ms
memory: 10892kb

input:

100
2000 1999
529 528
885 884
1221 1222
375 374
245 244
758 757
711 710
1521 1522
1875 1874
749 750
823 822
1959 1958
1767 1766
155 154
631 632
825 824
1330 1331
457 456
1344 1343
1817 1818
413 414
582 583
1828 1827
1335 1336
654 655
162 161
1668 1667
1966 1967
1472 1471
1185 1184
518 517
1509 1510
...

output:

44
1956 1911 1866 1821 1776 1731 1686 1641 1596 1551 1506 1461 1416 1371 1326 1281 1236 1191 1146 1101 1056 1011 966 921 876 831 786 741 696 651 606 561 516 471 426 381 336 291 246 201 156 111 66 21 
1
1
22
957 913 869 825 781 737 693 649 605 561 517 473 429 385 341 297 253 209 165 121 77 33 
5
1065...

result:

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