162412025-04-15 13:49:48lacitoKét csoportcpp17Accepted 100/100202ms21564 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
base100/100
1Accepted0/01ms316 KiB
2Accepted0/054ms7220 KiB
3Accepted3/31ms316 KiB
4Accepted3/31ms316 KiB
5Accepted3/31ms328 KiB
6Accepted3/31ms328 KiB
7Accepted3/31ms508 KiB
8Accepted2/21ms500 KiB
9Accepted3/31ms328 KiB
10Accepted3/32ms328 KiB
11Accepted3/31ms328 KiB
12Accepted3/36ms1088 KiB
13Accepted3/36ms1116 KiB
14Accepted3/37ms1088 KiB
15Accepted6/654ms7268 KiB
16Accepted7/759ms7484 KiB
17Accepted7/765ms7232 KiB
18Accepted6/6109ms14340 KiB
19Accepted6/6119ms14400 KiB
20Accepted6/6136ms14476 KiB
21Accepted6/6173ms21176 KiB
22Accepted7/7180ms21564 KiB
23Accepted7/7195ms21388 KiB
24Accepted7/7202ms21312 KiB