168042025-05-13 17:08:19algoproKét csoportcpp17Accepted 100/100140ms6452 KiB
// UUID: 765dbac9-eb06-45cb-90bc-774ce7944347
#include <bits/stdc++.h>
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<array<int, 3>> a(n + 2, {n + 1, n + 1, n + 1});
    vector<int> t(n + 2, 0);
    t[n + 1] = -1;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < 4; j++){
            int b;
            cin >> b;
            if(b != 0) a[i][j] = b;
            else break;
        }
    }
    for(int i = 1; i <= n; i++){
        int bad = i;
        t[i] = 0;
        while(true){
            int s = 0;
            for(int j = 0; j < 3; j++){
                s += (t[a[bad][j]] == t[bad]);
            }
            if(s >= 2){
                t[bad] = 1 - t[bad];
                for(int j = 0; j < 3; j++){
                    if(t[a[bad][j]] == t[bad]){
                        bad = a[bad][j];
                        break;
                    }
                }
            }
            else break;
        }
    }
    int ans = 0;
    for(int i = 1; i <= n; i++){
        if(t[i] == 0) ans++;  
    }
    cout << ans << "\n";
    for(int i = 1; i <= n; i++){
        if(t[i] == 0) cout << i << " ";  
    }
}
SubtaskSumTestVerdictTimeMemory
base100/100
1Accepted0/01ms316 KiB
2Accepted0/039ms2256 KiB
3Accepted3/31ms316 KiB
4Accepted3/31ms316 KiB
5Accepted3/31ms316 KiB
6Accepted3/31ms316 KiB
7Accepted3/31ms316 KiB
8Accepted2/21ms316 KiB
9Accepted3/31ms316 KiB
10Accepted3/31ms316 KiB
11Accepted3/31ms316 KiB
12Accepted3/34ms564 KiB
13Accepted3/34ms564 KiB
14Accepted3/34ms564 KiB
15Accepted6/639ms2252 KiB
16Accepted7/741ms2260 KiB
17Accepted7/745ms2260 KiB
18Accepted6/679ms4332 KiB
19Accepted6/682ms4244 KiB
20Accepted6/692ms4076 KiB
21Accepted6/6120ms6452 KiB
22Accepted7/7128ms6152 KiB
23Accepted7/7140ms5940 KiB
24Accepted7/7138ms6152 KiB