QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#139610#6634. Central SubsetFzArKWA 2ms8536kbC++172.3kb2023-08-14 03:42:232023-08-14 03:42:24

Judging History

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

  • [2023-08-14 03:42:24]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:8536kb
  • [2023-08-14 03:42:23]
  • 提交

answer

#include<bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sc(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define clr(x) vector<int>().swap(x);
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define endl '\n'
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define popf pop_front
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define random mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define F first
#define S second
const ll INF=1e18;
const ll MN=-2e9;
const ll MX=2e5+9;
const ll MXX=1e9;
const ll SQ=4e2;
const ll MOD=998244353;
const ll PP=1e6+3;
const ld PI=3.141592653589793;
const ld eps=1e-11;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update>
    ordered_set;

int n, m, q, p[MX], d[MX], vis[MX];
vector<int> I, ans, adj[MX];

void init() {
    q = 0;
    I.clear();
    ans.clear();
    for (int i=1; i<=n; i++) {
        adj[i].clear();
    }
}

void go(int u, int par) {
    if (vis[u]) return;
    vis[u] = 1;
    p[u] = par;
    d[u] = d[par] + 1;
    for (auto v:adj[u]) go(v, u);
}

void gg(int u) {
    if (!vis[u]) return;
    vis[u] = 0;
    for (auto v:adj[u]) if (v != p[u]) {
        gg(v);
    }
}

void solve() {
    cin >> n >> m;
    while (m--) {
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    go(1, 0);
    for (int i=1; i<=n; i++) I.pb(i);
    while (q*q < n) q++;
    sort (all(I), [&](int i, int j){
        if (d[i] == d[j]) return i < j;
        return d[i] > d[j];
    });
    for (auto v:I) if (!vis[v]) {
        for (int i=0; i<q; i++) {
            if (v == 1) break;
            v = p[v];
        }
        if (!vis[v]) continue;
        gg(v);
        ans.pb(v);
    }
    cout << sz(ans) << endl;
    for (auto x:ans) cout << x << " "; cout << endl;
    init();
}

int main() {
    FAST;
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
}

/*



*/

详细

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 8536kb

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:

0

0


result:

wrong answer Integer 0 violates the range [1, 2] (test case 1)