79442024-01-12 08:12:30BotiElágazás nélküli úton levő települések (50 pont)cpp17Accepted 50/5027ms4652 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)
        {
            if (count(o.begin(), o.end(), b[i]) == 0)
            {
                o.push_back(b[i]);
            }
            if (utak[b[i]] <= 2)
            {
                bejar(b[i], c);
            }
        }
        if (b[i] == c && a[i] != d)
        {
            if (count(o.begin(), o.end(), a[i]) == 0)
            {
                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);
        }
    }
    sort(o.begin(), o.end());
    cout << o.size() << endl;
    for (int i = 0; i < o.size(); i++)
    {
        cout << o[i] << " ";
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms2152 KiB
2Accepted0/026ms3000 KiB
3Accepted2/23ms2516 KiB
4Accepted2/23ms2484 KiB
5Accepted2/23ms2520 KiB
6Accepted2/23ms2748 KiB
7Accepted2/23ms2864 KiB
8Accepted2/24ms3136 KiB
9Accepted2/26ms3336 KiB
10Accepted2/28ms3632 KiB
11Accepted2/214ms4020 KiB
12Accepted2/214ms4132 KiB
13Accepted3/34ms3780 KiB
14Accepted3/36ms3716 KiB
15Accepted3/38ms3804 KiB
16Accepted3/321ms3680 KiB
17Accepted3/320ms3944 KiB
18Accepted3/325ms3952 KiB
19Accepted3/325ms4196 KiB
20Accepted3/325ms4476 KiB
21Accepted3/326ms4400 KiB
22Accepted3/327ms4652 KiB