71582024-01-01 09:33:02MagyarKendeSZLGParti (75 pont)cpp17Wrong answer 7/7535ms6548 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;
    vector<bool> vis(N + 1);

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

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

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

            if (vis[next]) continue;
            vis[next] = 1;

            if (--indegS[next] < 2) {
                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
base7/75
1Accepted0/03ms1828 KiB
2Wrong answer0/018ms3640 KiB
3Wrong answer0/33ms1992 KiB
4Accepted3/32ms1992 KiB
5Wrong answer0/33ms2132 KiB
6Wrong answer0/33ms2340 KiB
7Wrong answer0/33ms2564 KiB
8Wrong answer0/43ms2772 KiB
9Wrong answer0/43ms2996 KiB
10Wrong answer0/43ms2888 KiB
11Wrong answer0/43ms2860 KiB
12Wrong answer0/43ms2884 KiB
13Wrong answer0/43ms2956 KiB
14Wrong answer0/44ms2920 KiB
15Wrong answer0/418ms4544 KiB
16Wrong answer0/423ms4956 KiB
17Wrong answer0/425ms5496 KiB
18Wrong answer0/428ms5956 KiB
19Wrong answer0/432ms6160 KiB
20Wrong answer0/435ms6548 KiB
21Wrong answer0/435ms6416 KiB
22Accepted4/43ms3396 KiB