97602024-03-06 13:51:29FulopMateEmezen Rt.cpp17Wrong answer 0/1001.082s55740 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);
    for (int it = 0; it < n/50; 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
1Accepted6ms11260 KiB
subtask20/16
2Wrong answer6ms11448 KiB
3Accepted6ms11820 KiB
4Accepted6ms11832 KiB
5Accepted6ms11916 KiB
6Accepted6ms11924 KiB
7Wrong answer6ms12028 KiB
8Wrong answer6ms12036 KiB
9Accepted6ms12152 KiB
10Wrong answer6ms11888 KiB
11Wrong answer6ms12140 KiB
12Accepted6ms12088 KiB
13Accepted6ms12340 KiB
14Accepted6ms12556 KiB
15Accepted6ms12940 KiB
16Accepted6ms12848 KiB
subtask30/18
17Accepted96ms33472 KiB
18Accepted228ms55676 KiB
19Accepted226ms54412 KiB
20Accepted510ms15672 KiB
21Time limit exceeded1.075s21884 KiB
22Time limit exceeded1.055s27264 KiB
23Time limit exceeded1.069s30468 KiB
24Time limit exceeded1.064s30984 KiB
25Time limit exceeded1.06s32288 KiB
26Time limit exceeded1.064s32336 KiB
subtask40/66
27Accepted726ms17232 KiB
28Time limit exceeded1.075s12640 KiB
29Time limit exceeded1.062s16768 KiB
30Time limit exceeded1.082s27288 KiB
31Time limit exceeded1.067s32308 KiB
32Time limit exceeded1.072s32388 KiB
33Time limit exceeded1.077s31868 KiB
34Time limit exceeded1.064s31360 KiB
35Accepted244ms55740 KiB
36Accepted256ms55700 KiB
37Accepted8ms14492 KiB
38Accepted14ms16192 KiB
39Accepted28ms19992 KiB
40Accepted7ms14328 KiB
41Accepted7ms14616 KiB
42Accepted59ms16476 KiB
43Wrong answer28ms15140 KiB
44Wrong answer14ms14044 KiB
45Wrong answer8ms14000 KiB