57062023-09-09 18:10:03TomaSajtElágazás nélküli úton levő települések (50 pont)cpp17Wrong answer 6/5014ms5944 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
base6/50
1Wrong answer0/03ms2104 KiB
2Wrong answer0/014ms3976 KiB
3Wrong answer0/22ms2120 KiB
4Accepted2/22ms2244 KiB
5Accepted2/22ms2384 KiB
6Wrong answer0/22ms2476 KiB
7Wrong answer0/23ms2684 KiB
8Wrong answer0/23ms3108 KiB
9Wrong answer0/24ms3536 KiB
10Wrong answer0/26ms4080 KiB
11Accepted2/28ms4600 KiB
12Wrong answer0/28ms4664 KiB
13Wrong answer0/33ms4124 KiB
14Wrong answer0/34ms4252 KiB
15Wrong answer0/34ms4312 KiB
16Wrong answer0/34ms4500 KiB
17Wrong answer0/38ms4796 KiB
18Wrong answer0/38ms4820 KiB
19Wrong answer0/38ms5164 KiB
20Wrong answer0/314ms5376 KiB
21Wrong answer0/314ms5944 KiB
22Wrong answer0/314ms5900 KiB