#include <vector>
#include <iostream>
#include <set>
using namespace std;
vector<vector<int>> graf;
set<int> valasz;
int n, m;
void bejaras(int a) {        
    vector<int> vizsg;
    vizsg.push_back(a);
    bool tobb = false;
    vector<bool> volt(n+1);
    volt[a] = true;
    while (!tobb) {        
        for (int i = 1;i < n + 1;i++) {
            if (graf[vizsg[0]][i] == 1 && !volt[i]) {
                vizsg.push_back(i);
                volt[i] = true;
            }
        }
        vizsg.erase(vizsg.begin());
        if (vizsg.size() == 1) {
            valasz.insert(vizsg[0]);           
        else { tobb=true; }        
    }

  
}
int main()
{
    cin >> n >> m;
    vector<int> utak(n+1);
    graf.resize(n+1);
    for (int i = 1;i < n+1;i++) {
        graf[i].resize(n + 1);
    }
    for (int i = 1;i < m+1;i++) {        
        int egyik, masik;
        cin >> egyik >> masik;
        graf[egyik][masik] = 1;
        graf[masik][egyik] = 1;
        utak[egyik]++;
        utak[masik]++;
    }
    for (int i = 1;i < n + 1;i++) {
        if (utak[i] == 1) {
            bejaras(i);
        }
    }
    cout << valasz.size() << endl;
    if (valasz.size() != 0) {
        for (int x : valasz) {
            cout << x << " ";
        }
        cout << endl;
    }
}
Compilation error
exit status 1
main.cpp: In function 'void bejaras(int)':
main.cpp:24:9: error: expected '}' before 'else'
   24 |         else { tobb=true; }
      |         ^~~~
main.cpp:22:32: note: to match this '{'
   22 |         if (vizsg.size() == 1) {
      |                                ^
Exited with error status 1