57052023-09-09 18:07:20TomaSajtElágazás nélküli úton levő települések (50 pont)cpp17Wrong answer 2/5014ms9248 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);
  }

  cout << count(vis.begin(), vis.end(), 1) << '\n';
  for (int i = 1; i <= n; i++) {
    if (vis[i] && g[i].size() != 1) cout << i << ' ';
  }
}
SubtaskSumTestVerdictTimeMemory
base2/50
1Wrong answer0/03ms1888 KiB
2Wrong answer0/014ms4164 KiB
3Wrong answer0/23ms2628 KiB
4Wrong answer0/23ms2760 KiB
5Accepted2/23ms2996 KiB
6Wrong answer0/23ms3200 KiB
7Wrong answer0/22ms3264 KiB
8Wrong answer0/23ms3600 KiB
9Wrong answer0/24ms4064 KiB
10Wrong answer0/26ms4308 KiB
11Wrong answer0/28ms5088 KiB
12Wrong answer0/28ms5444 KiB
13Wrong answer0/33ms4872 KiB
14Wrong answer0/34ms5308 KiB
15Wrong answer0/34ms5624 KiB
16Wrong answer0/34ms6112 KiB
17Wrong answer0/37ms6576 KiB
18Wrong answer0/38ms6748 KiB
19Wrong answer0/38ms7512 KiB
20Wrong answer0/314ms8344 KiB
21Wrong answer0/314ms8984 KiB
22Wrong answer0/314ms9248 KiB