56272023-08-29 12:24:19TomaSajtParti (75 pont)cpp17Wrong answer 72/7568ms14696 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 << ' ';
}
SubtaskSumTestVerdictTimeMemory
base72/75
1Accepted0/03ms1812 KiB
2Accepted0/035ms4200 KiB
3Accepted3/32ms2536 KiB
4Accepted3/33ms2664 KiB
5Wrong answer0/32ms2884 KiB
6Accepted3/33ms3096 KiB
7Accepted3/33ms3316 KiB
8Accepted4/43ms3532 KiB
9Accepted4/43ms3884 KiB
10Accepted4/44ms4264 KiB
11Accepted4/43ms4368 KiB
12Accepted4/44ms4748 KiB
13Accepted4/44ms4636 KiB
14Accepted4/44ms4676 KiB
15Accepted4/435ms6920 KiB
16Accepted4/441ms7836 KiB
17Accepted4/450ms9180 KiB
18Accepted4/454ms10364 KiB
19Accepted4/463ms11944 KiB
20Accepted4/468ms13396 KiB
21Accepted4/468ms14696 KiB
22Accepted4/42ms11472 KiB