97662024-03-06 13:56:15FulopMateEmezen Rt.cpp17Wrong answer 0/100363ms61860 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();
        g2[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 < 80; 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
2Wrong answer6ms11516 KiB
3Accepted7ms11736 KiB
4Accepted7ms11944 KiB
5Accepted6ms12168 KiB
6Accepted6ms12408 KiB
7Wrong answer7ms12564 KiB
8Wrong answer7ms12764 KiB
9Accepted7ms12816 KiB
10Wrong answer6ms12936 KiB
11Wrong answer6ms12892 KiB
12Accepted6ms13024 KiB
13Accepted7ms13148 KiB
14Accepted7ms13276 KiB
15Accepted6ms13248 KiB
16Accepted7ms13248 KiB
subtask30/18
17Accepted90ms34140 KiB
18Accepted228ms56300 KiB
19Accepted199ms55348 KiB
20Wrong answer23ms16280 KiB
21Accepted152ms41900 KiB
22Accepted229ms52592 KiB
23Accepted305ms58700 KiB
24Accepted284ms59700 KiB
25Accepted293ms61860 KiB
26Accepted305ms61800 KiB
subtask40/66
27Wrong answer23ms16448 KiB
28Wrong answer41ms21820 KiB
29Accepted87ms30976 KiB
30Accepted263ms52424 KiB
31Accepted363ms61640 KiB
32Accepted305ms61652 KiB
33Accepted296ms60748 KiB
34Accepted337ms59792 KiB
35Wrong answer224ms55836 KiB
36Wrong answer224ms55868 KiB
37Wrong answer8ms14200 KiB
38Accepted13ms16084 KiB
39Wrong answer29ms19928 KiB
40Accepted8ms14544 KiB
41Wrong answer8ms14628 KiB
42Accepted71ms14056 KiB
43Wrong answer35ms14148 KiB
44Wrong answer16ms14172 KiB
45Wrong answer13ms14164 KiB