57072023-09-09 18:10:47TomaSajtElágazás nélküli úton levő települések (50 pont)cpp17Wrong answer 31/5014ms5596 KiB
#include <bits/stdc++.h>
using namespace std;

vector<bool> vis;
vector<vector<int>> g;

void dfs(int u) {
  if (vis[u]) return;
  vis[u] = 1;
  if (g[u].size() >= 3) return;
  for (int v : g[u]) dfs(v);
}

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

  int n, m;
  cin >> n >> m;
  g.resize(n + 1);
  vis.resize(n + 1);

  while (m--) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }

  for (int i = 1; i <= n; i++) {
    if (g[i].size() == 1) dfs(i);
  }

  vector<int> sol;
  for (int i = 1; i <= n; i++) {
    if (vis[i] && g[i].size() != 1) sol.push_back(i);
  }

  cout << sol.size() << '\n';
  for (int i : sol) cout << i << ' ';
}
SubtaskSumTestVerdictTimeMemory
base31/50
1Accepted0/03ms1832 KiB
2Accepted0/014ms3904 KiB
3Wrong answer0/23ms2260 KiB
4Accepted2/22ms2344 KiB
5Accepted2/23ms2548 KiB
6Wrong answer0/23ms2760 KiB
7Accepted2/23ms2984 KiB
8Accepted2/23ms3156 KiB
9Accepted2/24ms3620 KiB
10Accepted2/26ms3904 KiB
11Accepted2/28ms4296 KiB
12Accepted2/28ms4556 KiB
13Accepted3/33ms3960 KiB
14Wrong answer0/34ms3968 KiB
15Wrong answer0/34ms4100 KiB
16Wrong answer0/34ms4268 KiB
17Wrong answer0/38ms4564 KiB
18Wrong answer0/38ms4628 KiB
19Accepted3/39ms4976 KiB
20Accepted3/314ms5152 KiB
21Accepted3/314ms5468 KiB
22Accepted3/314ms5596 KiB