161992025-04-14 16:49:56algoproKét csoportcpp17Wrong answer 39/100195ms24172 KiB
// UUID: 0d619678-6b06-4705-8e27-a717d2df7d38
#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;
        }
    }
    vector<int> ord(n);
    iota(ord.begin(), ord.end(), 1);
    random_shuffle(ord.begin(), ord.end());
    for (int i : ord) {
        if (col[i] == -1) {
            col[i] = 0;
            dfs(i);
        }
    }
    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
base39/100
1Accepted0/07ms8508 KiB
2Accepted0/061ms12340 KiB
3Accepted3/38ms8500 KiB
4Accepted3/38ms8504 KiB
5Accepted3/37ms8616 KiB
6Accepted3/37ms8624 KiB
7Accepted3/38ms8500 KiB
8Wrong answer0/27ms8644 KiB
9Accepted3/39ms8688 KiB
10Wrong answer0/38ms8500 KiB
11Wrong answer0/38ms8696 KiB
12Accepted3/312ms8808 KiB
13Wrong answer0/314ms9016 KiB
14Wrong answer0/313ms9012 KiB
15Accepted6/659ms12340 KiB
16Wrong answer0/761ms12556 KiB
17Wrong answer0/767ms13460 KiB
18Accepted6/6112ms16096 KiB
19Wrong answer0/6120ms16508 KiB
20Wrong answer0/6128ms19056 KiB
21Accepted6/6163ms19984 KiB
22Wrong answer0/7178ms20532 KiB
23Wrong answer0/7195ms24172 KiB
24Wrong answer0/7189ms22832 KiB