97632024-03-06 13:53:20FulopMateEmezen Rt.cpp17Wrong answer 0/1001.077s61472 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 = 300;
    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
1Accepted7ms11408 KiB
subtask20/16
2Accepted6ms11592 KiB
3Accepted6ms11684 KiB
4Accepted6ms11824 KiB
5Accepted7ms12044 KiB
6Accepted6ms12392 KiB
7Accepted7ms12528 KiB
8Accepted7ms12496 KiB
9Accepted7ms12624 KiB
10Accepted7ms12784 KiB
11Wrong answer7ms12992 KiB
12Accepted6ms12904 KiB
13Accepted6ms12912 KiB
14Wrong answer7ms13140 KiB
15Accepted6ms13232 KiB
16Wrong answer7ms13164 KiB
subtask30/18
17Accepted160ms33924 KiB
18Accepted351ms56184 KiB
19Accepted389ms55264 KiB
20Accepted90ms16292 KiB
21Accepted653ms41760 KiB
22Accepted873ms52712 KiB
23Accepted767ms58684 KiB
24Time limit exceeded1.014s59996 KiB
25Time limit exceeded1.06s32816 KiB
26Time limit exceeded1.044s33012 KiB
subtask40/66
27Accepted114ms17992 KiB
28Accepted257ms23168 KiB
29Accepted446ms31660 KiB
30Accepted870ms52976 KiB
31Time limit exceeded1.077s33120 KiB
32Time limit exceeded1.059s33020 KiB
33Time limit exceeded1.036s61472 KiB
34Accepted945ms60412 KiB
35Accepted377ms56520 KiB
36Accepted379ms56480 KiB
37Accepted7ms14828 KiB
38Accepted25ms16688 KiB
39Accepted52ms20544 KiB
40Accepted8ms14892 KiB
41Accepted8ms15176 KiB
42Time limit exceeded1.069s9316 KiB
43Time limit exceeded1.067s9260 KiB
44Wrong answer98ms14632 KiB
45Wrong answer46ms14564 KiB