56282023-08-29 12:25:52TomaSajtParti (75 pont)cpp17Accepted 75/7568ms7100 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(0), ios::sync_with_stdio();

  int n;
  cin >> n;

  vector<array<int, 2>> g(n + 1);
  vector<int> in_deg(n + 1);

  for (int i = 1; i <= n; i++) {
    auto& [a, b] = g[i];
    cin >> a >> b;
    in_deg[a]++, in_deg[b]++;
  }

  queue<int> q;  // nodes for removal
  for (int i = 1; i <= n; i++) {
    if (in_deg[i] < 2) q.push(i);
  }

  while (!q.empty()) {
    int i = q.front();
    q.pop();
    auto& [a, b] = g[i];
    if (--in_deg[a] == 1) q.push(a);
    if (--in_deg[b] == 1) q.push(b);
  }

  vector<int> res;
  for (int i = 1; i <= n; i++) {
    if (in_deg[i] >= 2) res.push_back(i);
  }

  cout << res.size() << '\n';
  for (int i : res) cout << i << ' ';
  cout << '\n';
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/03ms1676 KiB
2Accepted0/035ms3560 KiB
3Accepted3/33ms2140 KiB
4Accepted3/33ms2356 KiB
5Accepted3/32ms2560 KiB
6Accepted3/33ms2812 KiB
7Accepted3/33ms3028 KiB
8Accepted4/43ms3180 KiB
9Accepted4/43ms3244 KiB
10Accepted4/44ms3628 KiB
11Accepted4/43ms3704 KiB
12Accepted4/44ms3804 KiB
13Accepted4/44ms4076 KiB
14Accepted4/44ms4164 KiB
15Accepted4/435ms5356 KiB
16Accepted4/441ms5616 KiB
17Accepted4/448ms5908 KiB
18Accepted4/457ms6312 KiB
19Accepted4/461ms6832 KiB
20Accepted4/468ms6848 KiB
21Accepted4/468ms7100 KiB
22Accepted4/42ms3864 KiB