161862025-04-13 18:01:20lacitoKét csoportcpp17Time limit exceeded 93/100202ms27300 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    vector<vector<int>> g(n + 1);
    vector<int> group(n + 1), hate_cnt(n + 1);
    queue<int> q_bad;
    for (int i = 1; i <= n; i++) {
        int x;
        for (cin >> x; x != 0; cin >> x) g[i].push_back(x);
        hate_cnt[i] = g[i].size();
        if (hate_cnt[i] > 1) q_bad.push(i);
    }
    while (!q_bad.empty()) {
        int p = q_bad.front(); q_bad.pop();
        if (hate_cnt[p] <= 1) continue;
        group[p] = 1 - group[p];
        hate_cnt[p] = g[p].size() - hate_cnt[p];
        for (int x : g[p]) {
            hate_cnt[x] = (group[x] == group[p] ? hate_cnt[x] + 1 : hate_cnt[x] - 1);
            if (hate_cnt[x] == 2) q_bad.push(x);
        }
    }
    cout << count(group.begin() + 1, group.end(), 0) << endl;
    for (int i = 1; i <= n; i++) if (group[i] == 0) cout << i << " ";
    cout << endl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base93/100
1Accepted0/01ms316 KiB
2Accepted0/054ms8500 KiB
3Accepted3/31ms316 KiB
4Accepted3/31ms332 KiB
5Accepted3/31ms316 KiB
6Accepted3/31ms316 KiB
7Accepted3/31ms316 KiB
8Accepted2/21ms316 KiB
9Accepted3/31ms316 KiB
10Accepted3/32ms508 KiB
11Accepted3/32ms540 KiB
12Accepted3/36ms1076 KiB
13Accepted3/36ms1076 KiB
14Accepted3/37ms1216 KiB
15Accepted6/657ms8652 KiB
16Accepted7/759ms8992 KiB
17Accepted7/764ms9092 KiB
18Accepted6/6116ms17204 KiB
19Accepted6/6120ms17716 KiB
20Accepted6/6133ms18232 KiB
21Accepted6/6178ms25744 KiB
22Accepted7/7189ms26676 KiB
23Accepted7/7199ms27188 KiB
24Time limit exceeded0/7202ms27300 KiB