162082025-04-14 17:00:45algoproKét csoportcpp17Wrong answer 53/100279ms25176 KiB
// UUID: d26adbfc-8573-4283-b95e-0efb76664fd3
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 300'001;

int col[MAXN];
vector<int> g[MAXN];

void dfs(int u) {
    for (int v : g[u]) {
        if (col[v] == -1) {
            col[v] = col[u] ^ 1;
            dfs(v);
        }
    }
}

void solve() {
    int n; cin >> n;
    fill(col, col+MAXN, -1);
    for (int i = 1; i <= n; i++) {
        int x; cin >> x;
        while (x) {
            g[i].emplace_back(x);
            cin >> x;
        }
    }

    for (int i = 1; i <= n; i++) {
        if (col[i] == -1) {
            col[i] = 0;
            dfs(i);
        }
    }

    for (int it = 0; it < 3; it++) {
        vector<int> ord(n);
        iota(ord.begin(), ord.end(), 1);
        random_shuffle(ord.begin(), ord.end());
        bool good = true;
        for (int i : ord) {
            int cnt = 0;
            for (int j : g[i]) {
                if (col[i] == col[j]) cnt++;
            }
            if (cnt > 1) col[i] ^= 1;
        }
    }

    cout << count(col+1, col+n+1, 0) << "\n";
    for (int i = 1; i <= n; i++) {
        if (col[i] == 0) cout << i << " ";
    }
    cout << "\n";
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) solve();
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base53/100
1Accepted0/08ms8500 KiB
2Accepted0/079ms12388 KiB
3Accepted3/37ms8500 KiB
4Accepted3/38ms8500 KiB
5Accepted3/38ms8500 KiB
6Accepted3/38ms8504 KiB
7Accepted3/38ms8636 KiB
8Accepted2/27ms8504 KiB
9Accepted3/39ms8540 KiB
10Accepted3/38ms8500 KiB
11Accepted3/38ms8500 KiB
12Accepted3/316ms9016 KiB
13Accepted3/314ms9012 KiB
14Accepted3/314ms9012 KiB
15Accepted6/674ms12436 KiB
16Wrong answer0/785ms12524 KiB
17Wrong answer0/793ms13940 KiB
18Accepted6/6146ms16152 KiB
19Accepted6/6157ms16664 KiB
20Wrong answer0/6187ms19400 KiB
21Time limit exceeded0/6239ms20008 KiB
22Time limit exceeded0/7237ms20368 KiB
23Time limit exceeded0/7261ms23340 KiB
24Time limit exceeded0/7279ms25176 KiB