71602024-01-01 09:36:58MagyarKendeSZLGParti (75 pont)cpp17Wrong answer 72/7530ms7480 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 main() {
    speed;

    int N;
    cin >> N;

    vector<point> g(N + 1);
    vector<int> indegS(N + 1);

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

    queue<int> q;

    for (int i = 1; i <= N; i++) {
        if (indegS[i] < 2) {
            q.push(i);
        }
    }

    while (!q.empty()) {
        int node = q.front();
        q.pop();

        for (int i = 0; i < 2; i++) {
            int next = g[node][i];

            if (--indegS[next] == 1) {
                q.push(next);
            }
        }
    }

    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/03ms1828 KiB
2Accepted0/017ms3828 KiB
3Accepted3/33ms2232 KiB
4Accepted3/33ms2444 KiB
5Wrong answer0/33ms2660 KiB
6Accepted3/33ms2872 KiB
7Accepted3/33ms3084 KiB
8Accepted4/43ms3300 KiB
9Accepted4/43ms3396 KiB
10Accepted4/43ms3672 KiB
11Accepted4/43ms3968 KiB
12Accepted4/43ms4060 KiB
13Accepted4/43ms4152 KiB
14Accepted4/44ms4088 KiB
15Accepted4/417ms5740 KiB
16Accepted4/418ms5896 KiB
17Accepted4/421ms6292 KiB
18Accepted4/425ms6528 KiB
19Accepted4/428ms7016 KiB
20Accepted4/430ms7108 KiB
21Accepted4/429ms7480 KiB
22Accepted4/43ms4116 KiB