QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#726456#6634. Central SubsetsyhyydsWA 12ms14256kbC++172.0kb2024-11-09 00:58:402024-11-09 00:58:40

Judging History

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

  • [2024-11-09 00:58:40]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:14256kb
  • [2024-11-09 00:58:40]
  • 提交

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],t[N];
int n, m;
int ans[N], cn = 0, d,dep[N],maxx=0,v[N];
void dfx(int u) 
{
    for (int k : g[u]) 
    {
        if (v[k]) continue;
        t[u].push_back(k);
        t[k].push_back(u);
        v[k] = 1;
        dfx(k);
    }
}
int dfs(int u, int fa)
{   
    dep[u] = dep[fa] + 1;
    maxx = max(maxx, dep[u]);
    int fg = 0,cx=0;
    for (int v : t[u]) 
    {

        if (v == fa) continue;
        cx=max(cx,dfs(v, u)+1);
        fg = 1;
    }
    if (cx == d+1) 
    {
        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++) g[i].clear(),v[i]=0,t[i].clear();
    for (int i = 1; i <= m; i++)
    {
        int u, v;
        scanf("%d%d", &u, &v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    v[1] = 1;
    dfx(1);
    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: 4ms
memory: 13704kb

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: 12ms
memory: 14256kb

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
7 6 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
13 7 1 
1
1
1
3 
1
...

result:

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