78642024-01-11 14:04:45csaron71Elágazás nélküli úton levő települések (50 pont)cpp17Accepted 50/5030ms6348 KiB
#include <bits/stdc++.h>

using namespace std;

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

void joe(int x, int y) {
    for (int sz : elek[x]) {
        if (sz==y) continue;
        vege[sz]=true;
        if (elek[sz].size()>=3) continue;
        joe(sz, x);
    }
}

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, -1);
        }
    }
    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
base50/50
1Accepted0/03ms1812 KiB
2Accepted0/030ms3872 KiB
3Accepted2/23ms2344 KiB
4Accepted2/23ms2368 KiB
5Accepted2/23ms2612 KiB
6Accepted2/23ms2620 KiB
7Accepted2/23ms2752 KiB
8Accepted2/24ms3172 KiB
9Accepted2/27ms3452 KiB
10Accepted2/28ms3728 KiB
11Accepted2/216ms4296 KiB
12Accepted2/216ms4560 KiB
13Accepted3/34ms3700 KiB
14Accepted3/34ms3896 KiB
15Accepted3/36ms3948 KiB
16Accepted3/37ms4180 KiB
17Accepted3/314ms4772 KiB
18Accepted3/314ms4720 KiB
19Accepted3/318ms5232 KiB
20Accepted3/329ms5768 KiB
21Accepted3/330ms6348 KiB
22Accepted3/330ms6276 KiB