71622024-01-01 09:41:14MagyarKendeSZLGParti (75 pont)cpp17Wrong answer 72/7548ms16196 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 << ' ';
    cout << '\n';
}
SubtaskSumTestVerdictTimeMemory
base72/75
1Accepted0/03ms1992 KiB
2Accepted0/024ms8456 KiB
3Accepted3/33ms2292 KiB
4Accepted3/33ms2508 KiB
5Wrong answer0/33ms2732 KiB
6Accepted3/33ms2764 KiB
7Accepted3/33ms2984 KiB
8Accepted4/43ms3096 KiB
9Accepted4/43ms3448 KiB
10Accepted4/43ms3504 KiB
11Accepted4/43ms3660 KiB
12Accepted4/44ms3856 KiB
13Accepted4/44ms3928 KiB
14Accepted4/44ms4256 KiB
15Accepted4/425ms9956 KiB
16Accepted4/428ms11124 KiB
17Accepted4/434ms12276 KiB
18Accepted4/437ms13492 KiB
19Accepted4/443ms14744 KiB
20Accepted4/448ms16124 KiB
21Accepted4/446ms16196 KiB
22Accepted4/43ms3816 KiB