97542024-03-06 13:13:09FulopMateEmezen Rt.cpp17Wrong answer 0/100252ms46500 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];

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;
    for (int i = 0; i < m; i++) {
        int u, v; cin >> 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 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
1Accepted4ms6632 KiB
subtask20/16
2Wrong answer4ms6840 KiB
3Accepted4ms6900 KiB
4Accepted4ms7072 KiB
5Accepted4ms7340 KiB
6Accepted4ms7296 KiB
7Wrong answer4ms7560 KiB
8Wrong answer4ms7508 KiB
9Accepted4ms7760 KiB
10Wrong answer4ms7704 KiB
11Wrong answer4ms7708 KiB
12Accepted4ms7704 KiB
13Accepted4ms7704 KiB
14Accepted4ms7708 KiB
15Accepted4ms8008 KiB
16Accepted4ms8056 KiB
subtask30/18
17Accepted76ms24044 KiB
18Accepted194ms39732 KiB
19Accepted179ms39648 KiB
20Wrong answer8ms10788 KiB
21Accepted101ms29792 KiB
22Accepted144ms38084 KiB
23Accepted202ms42264 KiB
24Accepted209ms44480 KiB
25Accepted243ms46132 KiB
26Accepted248ms46364 KiB
subtask40/66
27Wrong answer8ms11064 KiB
28Wrong answer20ms14796 KiB
29Accepted57ms21572 KiB
30Accepted180ms38616 KiB
31Accepted252ms46500 KiB
32Accepted222ms46500 KiB
33Accepted217ms45856 KiB
34Accepted240ms45212 KiB
35Wrong answer199ms40412 KiB
36Wrong answer199ms40404 KiB
37Wrong answer6ms9628 KiB
38Accepted9ms11004 KiB
39Wrong answer23ms14136 KiB
40Accepted4ms9716 KiB
41Wrong answer6ms9728 KiB
42Accepted52ms9916 KiB
43Wrong answer24ms10156 KiB
44Wrong answer8ms10252 KiB
45Wrong answer4ms10152 KiB