78262024-01-11 12:19:48gyjazminElágazás nélküli úton levő települések (50 pont)cpp17Runtime error 10/5035ms64848 KiB
#include <vector>
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
vector<vector<int>> graf;
vector<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.push_back(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);
        }
    }
    std::sort(valasz.begin(), valasz.end());
    cout << valasz.size() << endl;
    if (valasz.size() != 0) {
        for (int x : valasz) {
            cout << x << " ";
        }
        cout << endl;
    }
}
SubtaskSumTestVerdictTimeMemory
base10/50
1Accepted0/03ms1812 KiB
2Runtime error0/035ms64848 KiB
3Wrong answer0/23ms2232 KiB
4Wrong answer0/23ms2448 KiB
5Accepted2/23ms2696 KiB
6Accepted2/23ms2748 KiB
7Accepted2/23ms2880 KiB
8Accepted2/27ms11000 KiB
9Accepted2/217ms34756 KiB
10Runtime error0/227ms63568 KiB
11Runtime error0/227ms63364 KiB
12Runtime error0/228ms63148 KiB
13Wrong answer0/36ms11736 KiB
14Wrong answer0/317ms35284 KiB
15Runtime error0/325ms63020 KiB
16Runtime error0/332ms62784 KiB
17Runtime error0/328ms62752 KiB
18Runtime error0/328ms62676 KiB
19Runtime error0/328ms62652 KiB
20Runtime error0/328ms62644 KiB
21Runtime error0/332ms62404 KiB
22Runtime error0/328ms62392 KiB