QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#202106#6634. Central Subsetarseny_y#WA 0ms17240kbC++231.5kb2023-10-05 19:24:592023-10-05 19:24:59

Judging History

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

  • [2023-10-05 19:24:59]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:17240kb
  • [2023-10-05 19:24:59]
  • 提交

answer

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

#define int long long

const int MAXN = 2e5 + 10;

vector<int> g[MAXN], tr[MAXN];

int sq = 1;

int usd[MAXN];

void dfs(int v = 1) {
    usd[v] = true;
    for (auto &to : g[v]) {
        if (!usd[to]) {
            tr[v].push_back(to);
            dfs(to);
        }
    }
}

int in_ans[MAXN];

int up[MAXN];

void tree_dfs(int v = 1) {
    for (auto &to : tr[v]) tree_dfs(to);
    up[v] = 0;
    for (auto &to : tr[v]) {
        if (!in_ans[to]) {
            up[v] = max(up[v], up[to] + 1);
        }
    }
    if (up[v] > sq || v == 1) {
        in_ans[v] = true;
    }
}

int32_t main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        sq = 1;
        while (sq * sq < n) ++sq;
        for (int i = 1; i <= n; ++i) g[i].clear(), tr[i].clear(), usd[i] = false, in_ans[i] = false, up[i] = 0;
        int m;
        cin >> m;
        for (int i = 0, x, y; i < m; ++i) {
            cin >> x >> y;
            g[x].push_back(y);
            g[y].push_back(x);
        }
        dfs(), tree_dfs();
        vector<int> ans;
        for (int i = 1; i <= n; ++i) {
            if (in_ans[i]) ans.push_back(i);
        }
        if (ans.size() > sq) {
            cout << "-1\n";
            continue;
        }
        cout << ans.size() << '\n';
        for (auto &el : ans) cout << el << ' ';
        cout << '\n';
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 17240kb

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

result:

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