97712024-03-06 14:00:30FulopMateEmezen Rt.cpp17Wrong answer 0/100990ms61644 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 < 3000; 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
1Accepted7ms11136 KiB
subtask20/16
2Wrong answer6ms11296 KiB
3Accepted6ms11556 KiB
4Accepted7ms11768 KiB
5Accepted6ms12028 KiB
6Accepted6ms12240 KiB
7Wrong answer7ms12492 KiB
8Wrong answer7ms12512 KiB
9Accepted6ms12576 KiB
10Wrong answer7ms12912 KiB
11Wrong answer6ms12968 KiB
12Accepted6ms13128 KiB
13Accepted6ms12996 KiB
14Accepted6ms12956 KiB
15Accepted6ms13088 KiB
16Accepted6ms13016 KiB
subtask30/18
17Accepted97ms33652 KiB
18Accepted211ms55852 KiB
19Accepted211ms54708 KiB
20Wrong answer601ms16292 KiB
21Accepted782ms41444 KiB
22Accepted873ms52092 KiB
23Accepted634ms58340 KiB
24Accepted781ms59508 KiB
25Accepted990ms61644 KiB
26Accepted948ms61596 KiB
subtask40/66
27Wrong answer669ms17336 KiB
28Wrong answer685ms22444 KiB
29Accepted731ms30892 KiB
30Accepted873ms52276 KiB
31Accepted954ms61632 KiB
32Accepted980ms61576 KiB
33Accepted921ms60664 KiB
34Accepted819ms59744 KiB
35Wrong answer222ms55856 KiB
36Wrong answer233ms55788 KiB
37Wrong answer8ms14332 KiB
38Accepted19ms16148 KiB
39Wrong answer34ms19948 KiB
40Accepted8ms14336 KiB
41Wrong answer8ms14524 KiB
42Accepted837ms13924 KiB
43Wrong answer540ms13924 KiB
44Wrong answer375ms13992 KiB
45Wrong answer349ms14012 KiB