78482024-01-11 13:17:19csaron71Elágazás nélküli úton levő települések (50 pont)cpp17Wrong answer 4/5029ms5840 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
base4/50
1Wrong answer0/03ms1808 KiB
2Wrong answer0/028ms3928 KiB
3Accepted2/23ms2384 KiB
4Wrong answer0/23ms2432 KiB
5Accepted2/23ms2660 KiB
6Wrong answer0/23ms2692 KiB
7Wrong answer0/23ms2916 KiB
8Wrong answer0/24ms3312 KiB
9Wrong answer0/26ms3472 KiB
10Wrong answer0/28ms3904 KiB
11Wrong answer0/216ms4548 KiB
12Wrong answer0/216ms4688 KiB
13Wrong answer0/34ms3744 KiB
14Wrong answer0/34ms3860 KiB
15Wrong answer0/36ms4276 KiB
16Wrong answer0/37ms4440 KiB
17Wrong answer0/314ms4892 KiB
18Wrong answer0/314ms4944 KiB
19Wrong answer0/317ms5320 KiB
20Wrong answer0/328ms5528 KiB
21Wrong answer0/329ms5840 KiB
22Wrong answer0/328ms5836 KiB