162412025-04-15 13:49:48lacitoKét csoportcpp17Elfogadva 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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base100/100
1Elfogadva0/01ms316 KiB
2Elfogadva0/054ms7220 KiB
3Elfogadva3/31ms316 KiB
4Elfogadva3/31ms316 KiB
5Elfogadva3/31ms328 KiB
6Elfogadva3/31ms328 KiB
7Elfogadva3/31ms508 KiB
8Elfogadva2/21ms500 KiB
9Elfogadva3/31ms328 KiB
10Elfogadva3/32ms328 KiB
11Elfogadva3/31ms328 KiB
12Elfogadva3/36ms1088 KiB
13Elfogadva3/36ms1116 KiB
14Elfogadva3/37ms1088 KiB
15Elfogadva6/654ms7268 KiB
16Elfogadva7/759ms7484 KiB
17Elfogadva7/765ms7232 KiB
18Elfogadva6/6109ms14340 KiB
19Elfogadva6/6119ms14400 KiB
20Elfogadva6/6136ms14476 KiB
21Elfogadva6/6173ms21176 KiB
22Elfogadva7/7180ms21564 KiB
23Elfogadva7/7195ms21388 KiB
24Elfogadva7/7202ms21312 KiB