78472024-01-11 13:15:44csaron71Elágazás nélküli úton levő települések (50 pont)cpp17Wrong answer 31/5030ms5088 KiB
#include <bits/stdc++.h>

using namespace std;

vector<bool> vege;
    vector<vector<int> > elek;

void joe(int x) {
    if (vege[x]!=true){
        vege[x]=true;
        if (elek[x].size()<=2) {
            for (int sz : elek[x]) {
                joe(sz);
            }
        }

    }
}

int main()
{
    int n, m;
    cin >> n >> m;elek.assign(n, vector<int>());
    for (int i=0; i<m; i++) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        elek[x].push_back(y);
        elek[y].push_back(x);
    }
    vege.assign(n, false);
    for (int i=0; i<n; i++) {
        if (elek[i].size()==1) {
            joe(i);
            vege[i]=false;
        }
    }
    int ossz=0;
    for (int i=0; i<n; i++) {
        if (vege[i]==true) {
            ossz++;
        }
    }
    cout << ossz << "\n";
    for (int i=0; i<n; i++) {
        if (vege[i]==true) {
            cout << i+1 << " ";
        }
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base31/50
1Accepted0/03ms1812 KiB
2Accepted0/030ms3928 KiB
3Wrong answer0/23ms2396 KiB
4Accepted2/23ms2260 KiB
5Accepted2/23ms2292 KiB
6Wrong answer0/23ms2416 KiB
7Accepted2/23ms2524 KiB
8Accepted2/24ms2868 KiB
9Accepted2/27ms3288 KiB
10Accepted2/28ms3472 KiB
11Accepted2/216ms3728 KiB
12Accepted2/217ms3772 KiB
13Accepted3/34ms2964 KiB
14Wrong answer0/34ms3156 KiB
15Wrong answer0/36ms3220 KiB
16Wrong answer0/37ms3424 KiB
17Wrong answer0/314ms3616 KiB
18Wrong answer0/314ms3896 KiB
19Accepted3/318ms4488 KiB
20Accepted3/329ms4692 KiB
21Accepted3/330ms5012 KiB
22Accepted3/330ms5088 KiB