97622024-03-06 13:52:35FulopMateEmezen Rt.cpp17Wrong answer 18/1001.062s62300 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define MAX(a, b) (a) = max((a), (b))
#define MIN(a, b) (a) = min((a), (b))
#define all(a) (a).begin(), (a).end()
#define sortedpair(a, b) {min((a), (b)), max((a), (b))}

const ll MOD = 1e9+7;

const int MAXN = 100'001;

struct E {
    int u, v, w;

    E(int a, int b, int c) : u(a), v(b), w(c) {}
};

int par[MAXN], ans[MAXN];
vector<int> g[MAXN], g2[MAXN];

int get(int u) {
    if (par[u] == u) return u;
    return par[u]=get(par[u]);
}

bool unio(int u, int v) {
    u = get(u); v=get(v);
    if (u == v) return false;
    par[u]=v;
    return true;
}

void dfs(int u, int p = -1, int d = 0) {
    ans[u] = d&1;
    for (int v : g[u]) {
        if (v != p) dfs(v, u, d+1);
    }
}

void solve(){
    int n, m; cin>>n>>m;
    iota(par, par+n+1, 0);
    map<pair<int, int>, int> mp;
    vector<pair<int, int>> a;
    for (int i = 0; i < m; i++) {
        int u, v; cin >> u >> v;
        g2[u].emplace_back(v);
        g2[v].emplace_back(u);
        a.emplace_back(u, v);
        if (u > v) swap(u, v);
        mp[{u, v}]++;
    }
    for (int i = 1; i <= n; i++) {
        g[i].clear();
    }

    vector<E> edges;
    for (auto [e, x] : mp) {
        edges.emplace_back(e.first, e.second, x);
    }
    sort(edges.begin(), edges.end(), [](auto x, auto y){
        return x.w > y.w;
    });
    for (E e : edges) {
        if (unio(e.u, e.v)) {
            g[e.u].emplace_back(e.v);
            g[e.v].emplace_back(e.u);
        }
    }
    dfs(1);
    int x = 0;
    if (n <= 200) x = 20;
    else x = 100;
    for (int it = 0; it < x; it++) {
        for (int i = 1; i <= n; i++) {
            int cnt = 0;
            for (int u : g2[i]) {
                cnt += (ans[u]==ans[i]);
            }
            if (cnt > g2[i].size()/2) {
                ans[i] ^= 1;
            }
        }
    }
    int cnt = count(ans+1, ans+n+1, 1);
    cout << cnt << "\n";
    for (int i = 1; i <= n; i++) {
        if (ans[i]) cout << i << " ";
    }
    cout << "\n";
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int _t = 1;
    cin >> _t;
    while (_t--) {
        solve();
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted6ms11536 KiB
subtask20/16
2Accepted7ms11776 KiB
3Accepted6ms11712 KiB
4Accepted6ms11884 KiB
5Accepted7ms12136 KiB
6Accepted6ms12232 KiB
7Accepted6ms12356 KiB
8Accepted6ms12384 KiB
9Accepted6ms12616 KiB
10Accepted6ms12704 KiB
11Wrong answer7ms12964 KiB
12Accepted7ms13180 KiB
13Accepted7ms13344 KiB
14Wrong answer6ms13432 KiB
15Accepted6ms13432 KiB
16Wrong answer6ms13304 KiB
subtask318/18
17Accepted119ms33940 KiB
18Accepted254ms56144 KiB
19Accepted287ms55196 KiB
20Accepted39ms16220 KiB
21Accepted321ms42052 KiB
22Accepted432ms52736 KiB
23Accepted493ms58740 KiB
24Accepted521ms59936 KiB
25Accepted663ms62056 KiB
26Accepted563ms62232 KiB
subtask40/66
27Accepted46ms17652 KiB
28Accepted107ms23232 KiB
29Accepted197ms31644 KiB
30Accepted504ms52968 KiB
31Accepted564ms62292 KiB
32Accepted564ms62300 KiB
33Accepted535ms61372 KiB
34Accepted589ms60352 KiB
35Accepted303ms56396 KiB
36Accepted280ms56348 KiB
37Accepted8ms14776 KiB
38Accepted17ms16632 KiB
39Accepted35ms20432 KiB
40Accepted7ms14828 KiB
41Accepted8ms15056 KiB
42Time limit exceeded1.06s9100 KiB
43Time limit exceeded1.062s9056 KiB
44Wrong answer98ms14520 KiB
45Wrong answer19ms14460 KiB