70842023-12-30 09:16:10MagyarKendeSZLGParti (75 pont)cpp17Wrong answer 72/7552ms15840 KiB
#include <bits/stdc++.h>

#define speed cin.tie(0); ios::sync_with_stdio(0)
#define cinv(v) for (auto& e : v) cin >> e;
#define all(v) v.begin(), v.end()
#define has(s, e) s.count(e)

using namespace std;
using ll = long long;
using point = array<int, 2>;

int N;
vector<vector<int>> g;
vector<int> indegS;

void remove(int node, int deg) {
    indegS[node] = -1;
    for (int neighbor : g[node]) {
        indegS[neighbor]--;
        if (!indegS[neighbor]) {
            remove(neighbor, deg);
        }
    }
}

int main() {
    speed;

    cin >> N;
    g.resize(N + 1);
    indegS.resize(N + 1);

    for (int i = 1; i <= N; i++) {
        int U, V;
        cin >> U >> V;
        g[i].push_back(U);
        g[i].push_back(V);
        indegS[U]++;
        indegS[V]++;
    }

    for (int i = 0; i < 2; i++) {
        for (int node = 1; node <= N; node++) {
            if (indegS[node] == i) {
                remove(node, i);
            }
        }
    }

    vector<int> result;

    for (int i = 1; i <= N; i++) {
        if (indegS[i] >= 2) {
            result.push_back(i);
        }
    }

    cout << result.size() << '\n';
    for (int n : result) cout << n << ' ';
}
SubtaskSumTestVerdictTimeMemory
base72/75
1Accepted0/03ms1976 KiB
2Accepted0/027ms8464 KiB
3Accepted3/33ms2360 KiB
4Accepted3/33ms2604 KiB
5Wrong answer0/33ms2524 KiB
6Accepted3/33ms2752 KiB
7Accepted3/33ms2868 KiB
8Accepted4/43ms2980 KiB
9Accepted4/43ms3008 KiB
10Accepted4/44ms3336 KiB
11Accepted4/43ms3216 KiB
12Accepted4/43ms3452 KiB
13Accepted4/44ms3740 KiB
14Accepted4/44ms3944 KiB
15Accepted4/426ms9712 KiB
16Accepted4/430ms10952 KiB
17Accepted4/435ms12264 KiB
18Accepted4/441ms13376 KiB
19Accepted4/445ms14616 KiB
20Accepted4/450ms15840 KiB
21Accepted4/452ms15836 KiB
22Accepted4/43ms3724 KiB