77012024-01-10 13:48:10AblablablaElágazás nélküli úton levő települések (50 pont)cpp17Runtime error 6/5029ms6164 KiB
#include <bits/stdc++.h>

using namespace std;

vector<bool> bejart;
vector<vector<int>> csucsok;
vector<int> megoldas;

void dfs(int akt, int elozo){
    if(!bejart[akt]){
        megoldas.push_back(akt);
    }

    bejart[akt] = 1;

    if(csucsok[akt].size() > 2){
        return;
    }

    for(int x : csucsok[akt]){
        if(x == elozo) continue;

        dfs(x, akt);
    }
}

int main()
{
    int n, m;
    cin >> n >> m;

    csucsok.assign(n, vector<int>());
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;

        csucsok[a].push_back(b);
        csucsok[b].push_back(a);
    }

    bejart.assign(n, 0);

    for(int i = 0; i < n; i++){
        if(csucsok[i].size() > 1) continue;

        dfs(csucsok[i][0], i);
    }

    cout << megoldas.size() << "\n";
    for(int x : megoldas){
        cout << x + 1 << " ";
    }
    cout << "\n";
}
SubtaskSumTestVerdictTimeMemory
base6/50
1Accepted0/03ms1808 KiB
2Runtime error0/029ms3928 KiB
3Wrong answer0/23ms2132 KiB
4Accepted2/23ms2312 KiB
5Accepted2/23ms2400 KiB
6Runtime error0/23ms2620 KiB
7Wrong answer0/23ms2740 KiB
8Runtime error0/24ms3000 KiB
9Runtime error0/27ms3208 KiB
10Runtime error0/28ms3424 KiB
11Accepted2/216ms3932 KiB
12Runtime error0/216ms4100 KiB
13Runtime error0/34ms3464 KiB
14Runtime error0/34ms3868 KiB
15Runtime error0/36ms3728 KiB
16Runtime error0/36ms4080 KiB
17Runtime error0/314ms4856 KiB
18Runtime error0/314ms4824 KiB
19Runtime error0/317ms5272 KiB
20Wrong answer0/328ms5400 KiB
21Runtime error0/328ms6012 KiB
22Runtime error0/329ms6164 KiB