169182025-05-15 18:20:30algoproKét csoportcpp17Runtime error 0/100151ms64000 KiB
// UUID: b4167bc3-7f45-4136-9153-4361aabdbdd5
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pii pair<int, int>
#define fi first
#define se second

vector<int> v;
vector<bool> cs;
vector<vector<int>> adj;
queue<int> q;

void refresh(int x) {
    v[x]=0;
    for (int u : adj[x]) {
        v[x]+=(cs[x]==cs[u]);
    }
}

signed main() {
	int n;
    cin >> n;
    cs.resize(n+1);
    v.resize(n+1);
    adj.resize(n+1);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    for (int i = 1; i <= n; i++) {
        int u;
        cin >> u;
        while (u!=0) {
            if (u>i) {
                adj[i].push_back(u);
                adj[u].push_back(i);
            }
        }
    } // én nem értem mi történik
    //az inputon futtatod?
    for (int i = 1; i <= n; i++) {
        refresh(i);
        if (v[i]>1)q.push(i);
    }
    
    while (!q.empty()) {
        int x = q.front();
        q.pop();
        refresh(x);
        if (v[x]<=1)continue;
        cs[x]=!cs[x];
        for (int u : adj[x]) {
            refresh(u);
            if (v[u]>1) q.push(u);
        }
    }
    int m = 0;
    vector<int> ansv;
    for (int i = 1; i <= n; i++) {
        if (cs[i]==0) {
            m++;
            ansv.push_back(i);
        }
    }
    cout << m << endl;
    for (int x : ansv)cout << x << ' ';
}
SubtaskSumTestVerdictTimeMemory
base0/100
1Runtime error0/0146ms64000 KiB
2Runtime error0/0115ms64000 KiB
3Runtime error0/3146ms64000 KiB
4Runtime error0/3114ms64000 KiB
5Runtime error0/3151ms64000 KiB
6Runtime error0/3118ms64000 KiB
7Runtime error0/3145ms64000 KiB
8Runtime error0/2116ms64000 KiB
9Runtime error0/3119ms64000 KiB
10Runtime error0/3149ms64000 KiB
11Runtime error0/3146ms64000 KiB
12Runtime error0/3145ms64000 KiB
13Runtime error0/3119ms64000 KiB
14Runtime error0/3115ms64000 KiB
15Runtime error0/6148ms64000 KiB
16Runtime error0/7114ms64000 KiB
17Runtime error0/7145ms64000 KiB
18Runtime error0/6112ms64000 KiB
19Runtime error0/6112ms64000 KiB
20Runtime error0/6145ms64000 KiB
21Runtime error0/6112ms64000 KiB
22Runtime error0/7112ms64000 KiB
23Runtime error0/7143ms64000 KiB
24Runtime error0/7136ms64000 KiB