79412024-01-12 08:04:59BotiElágazás nélküli úton levő települések (50 pont)cpp17Wrong answer 4/5027ms4376 KiB
#include <bits/stdc++.h>

using namespace std;

int n, m;
vector<int> a;
vector<int> b;
vector<int> utak;
vector<int> o (0);

void bejar(int c, int d)
{
    for (int i = 0; i < m; i++)
    {
        if (a[i] == c && b[i] != d)
        {
            o.push_back(b[i]);
            if (utak[b[i]] <= 2)
            {
                bejar(b[i], c);
            }
        }
        if (b[i] == c && a[i] != d)
        {
            o.push_back(a[i]);
            if (utak[a[i]] <= 2)
            {
                bejar(a[i], c);
            }
        }
    }
}

int main()
{
    cin >> n >> m;
    a.resize(m);
    b.resize(m);
    utak.resize(n +1, 0);
    for (int i = 0; i < m; i++)
    {
        cin >> a[i] >> b[i];
        utak[a[i]]++;
        utak[b[i]]++;
    }
    for (int i = 1; i <= n; i++)
    {
        if (utak[i] == 1)
        {
            bejar(i, -1);
        }
    }
    cout << o.size() << endl;
    for (int i = 0; i < o.size(); i++)
    {
        cout << o[i] << " ";
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base4/50
1Accepted0/03ms1880 KiB
2Wrong answer0/026ms2764 KiB
3Wrong answer0/23ms2556 KiB
4Wrong answer0/23ms2616 KiB
5Accepted2/23ms2816 KiB
6Wrong answer0/23ms2824 KiB
7Wrong answer0/23ms2736 KiB
8Wrong answer0/24ms2968 KiB
9Wrong answer0/26ms3280 KiB
10Wrong answer0/28ms3528 KiB
11Accepted2/213ms3684 KiB
12Wrong answer0/214ms3684 KiB
13Wrong answer0/34ms3532 KiB
14Wrong answer0/36ms3556 KiB
15Wrong answer0/38ms3852 KiB
16Wrong answer0/319ms3736 KiB
17Wrong answer0/319ms3948 KiB
18Wrong answer0/325ms3968 KiB
19Wrong answer0/325ms4016 KiB
20Wrong answer0/325ms4376 KiB
21Wrong answer0/326ms4308 KiB
22Wrong answer0/327ms4312 KiB