QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#497583#6634. Central SubsetrgnerdplayerWA 19ms3808kbC++201.3kb2024-07-29 14:26:072024-07-29 14:26:09

Judging History

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

  • [2024-07-29 14:26:09]
  • 评测
  • 测评结果:WA
  • 用时:19ms
  • 内存:3808kb
  • [2024-07-29 14:26:07]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using i64 = long long;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    int t;
    cin >> t;

    auto solve = [&]() {
        int n, m;
        cin >> n >> m;

        vector<vector<int>> adj(n);
        for (int i = 0; i < m; i++) {
            int u, v;
            cin >> u >> v;
            u--, v--;
            adj[u].push_back(v);
            adj[v].push_back(u);
        }

        vector<int> vis(n), dep(n);
        int sq = sqrt(n);
        vector<vector<int>> verts(sq);

        auto dfs = [&](auto dfs, int u) -> void {
            verts[dep[u] % sq].push_back(u);
            vis[u] = true;
            for (auto v : adj[u]) {
                if (!vis[v]) {
                    dep[v] = dep[u] + 1;
                    dfs(dfs, v);
                }
            }
        };
        dfs(dfs, 0);

        int x = 0;
        for (int i = 0; i < sq; i++) {
            if (!verts[i].empty() && verts[i].size() < verts[x].size()) {
                x = i;
            }
        }

        cout << verts[x].size() << '\n';
        for (auto u : verts[x]) {
            cout << u + 1 << " \n"[u == verts[x].back()];
        }
    };

    while (t--) {
        solve();
    }
    
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3808kb

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
1 3
3
1 3 5

result:

ok correct (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 19ms
memory: 3620kb

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:

5
1 4 7 10 13
3
1 4 3
3
1 8 4
2
1 2
2
1 2
3
1 4 7
2
1 2
4
9 3 6 12
3
3 12 11
1
1
5
1 5 9 13 17
4
1 3 6 7
3
1 4 8
3
2 10 9
1
2
5
1 4 7 10 13
3
1 4 3
2
1 2
2
2 9
1
1
2
1 3
4
1 3 6 5
4
9 3 6 12
3
2 12 11
1
2
5
1 4 7 10 13
3
1 3 5
3
2 6 13
3
1 2 3
1
2
5
2 6 10 14 18
3
1 8 5
4
9 3 6 12
3
2 11 10
1
2
3
1 ...

result:

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