97592024-03-06 13:49:57FulopMateEmezen Rt.cpp17Wrong answer 18/1001.074s62272 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);
    for (int it = 0; it < 100; 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
1Accepted6ms11264 KiB
subtask20/16
2Accepted6ms11648 KiB
3Accepted6ms11620 KiB
4Accepted4ms11628 KiB
5Accepted7ms11756 KiB
6Accepted6ms11888 KiB
7Accepted7ms12116 KiB
8Accepted7ms12320 KiB
9Accepted7ms12492 KiB
10Accepted7ms12700 KiB
11Wrong answer6ms12912 KiB
12Accepted6ms13164 KiB
13Accepted6ms13244 KiB
14Wrong answer6ms13332 KiB
15Accepted7ms13588 KiB
16Wrong answer6ms13708 KiB
subtask318/18
17Accepted112ms34560 KiB
18Accepted250ms56676 KiB
19Accepted263ms55596 KiB
20Accepted35ms16620 KiB
21Accepted273ms42324 KiB
22Accepted363ms52912 KiB
23Accepted425ms59016 KiB
24Accepted469ms60196 KiB
25Accepted532ms62272 KiB
26Accepted541ms62212 KiB
subtask40/66
27Accepted45ms17772 KiB
28Accepted101ms23088 KiB
29Accepted195ms31328 KiB
30Accepted423ms52664 KiB
31Accepted686ms61984 KiB
32Accepted555ms61988 KiB
33Accepted523ms61060 KiB
34Accepted500ms60104 KiB
35Accepted261ms56164 KiB
36Accepted254ms56116 KiB
37Accepted7ms14532 KiB
38Accepted16ms16396 KiB
39Accepted35ms20192 KiB
40Accepted7ms14532 KiB
41Accepted8ms14784 KiB
42Time limit exceeded1.06s8752 KiB
43Time limit exceeded1.074s8780 KiB
44Wrong answer449ms14252 KiB
45Wrong answer17ms14204 KiB