69432023-12-21 07:42:35MagyarKendeSZLGElágazás nélküli úton levő települések (50 pont)cpp17Wrong answer 25/5014ms5204 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <unistd.h>

using namespace std;
#define speed cin.tie(0); ios::sync_with_stdio(0)

vector<vector<int>> neighborS;
vector<int> result;

void dfs(int node, int parent) {
    for (int neighbor : neighborS[node]) {
        if (neighbor == parent) continue;
        result.push_back(neighbor);
        if (neighborS[neighbor].size() > 2) continue;
        dfs(neighbor, node);
    }
}

int main() {
    speed;

    int N, M;
    cin >> N >> M;

    neighborS.resize(N + 1);
    
    while (M--) {
        int U, V;
        cin >> U >> V;
        neighborS[U].push_back(V);
        neighborS[V].push_back(U);
    }

    for (int i = 1; i <= N; i++) {
        if (neighborS[i].size() == 1) { // zsakfalu
            dfs(i, 0);
        }
    }
    
    if (result.empty()) {
        cout << 0;
        exit(0);
    }

    sort(result.begin(), result.end());

    cout << result.size() << '\n';
    for (int i = 0; i < result.size(); i++) {
        cout << result[i] << ' ';
    }
}
SubtaskSumTestVerdictTimeMemory
base25/50
1Accepted0/03ms1888 KiB
2Accepted0/014ms3972 KiB
3Wrong answer0/23ms2612 KiB
4Wrong answer0/23ms2568 KiB
5Accepted2/23ms2784 KiB
6Accepted2/23ms2860 KiB
7Accepted2/23ms2972 KiB
8Accepted2/24ms3008 KiB
9Accepted2/24ms3224 KiB
10Accepted2/26ms3568 KiB
11Accepted2/28ms3932 KiB
12Accepted2/28ms4056 KiB
13Wrong answer0/33ms3068 KiB
14Wrong answer0/34ms3536 KiB
15Wrong answer0/34ms3664 KiB
16Wrong answer0/34ms4012 KiB
17Wrong answer0/38ms4256 KiB
18Wrong answer0/38ms4288 KiB
19Wrong answer0/39ms4628 KiB
20Accepted3/314ms4980 KiB
21Accepted3/314ms5144 KiB
22Accepted3/314ms5204 KiB