97642024-03-06 13:54:00FulopMateEmezen Rt.cpp17Wrong answer 0/1001.052s60600 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;
    for (int it = 0; it < sqrt(n); 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
1Accepted7ms11260 KiB
subtask20/16
2Accepted6ms11512 KiB
3Accepted6ms11668 KiB
4Accepted7ms11888 KiB
5Accepted7ms12096 KiB
6Accepted7ms12316 KiB
7Accepted7ms12528 KiB
8Accepted6ms12608 KiB
9Accepted6ms12848 KiB
10Accepted6ms13056 KiB
11Wrong answer7ms13068 KiB
12Accepted7ms13064 KiB
13Accepted6ms13172 KiB
14Wrong answer6ms13172 KiB
15Accepted6ms13044 KiB
16Wrong answer6ms13044 KiB
subtask30/18
17Accepted98ms33700 KiB
18Accepted256ms55912 KiB
19Accepted261ms54552 KiB
20Accepted83ms15692 KiB
21Accepted657ms41092 KiB
22Accepted871ms52040 KiB
23Accepted708ms58092 KiB
24Accepted833ms59200 KiB
25Time limit exceeded1.016s31852 KiB
26Time limit exceeded1.036s31980 KiB
subtask40/66
27Accepted115ms17108 KiB
28Accepted256ms22288 KiB
29Accepted453ms30456 KiB
30Time limit exceeded1.019s51920 KiB
31Time limit exceeded1.052s32072 KiB
32Time limit exceeded1.049s32164 KiB
33Accepted999ms60600 KiB
34Time limit exceeded1.049s31220 KiB
35Accepted263ms55680 KiB
36Accepted252ms55560 KiB
37Accepted8ms14236 KiB
38Accepted14ms16056 KiB
39Accepted32ms19912 KiB
40Accepted8ms14248 KiB
41Accepted8ms14544 KiB
42Time limit exceeded1.042s9248 KiB
43Time limit exceeded1.039s8884 KiB
44Wrong answer46ms13976 KiB
45Wrong answer9ms13952 KiB