39762023-03-07 12:31:45bzsofiaElágazás nélküli úton levő települések (50 pont)cpp11Wrong answer 18/5048ms64172 KiB
// elagaz.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct adat
{
    bool lat;
    vector <int> sz;
};

vector <int> v;
vector <adat> x;
long long n, i, m, a, b;

void mely(int csp, int kezd)
{
    v.push_back(csp);

    if (x[csp].sz.size() == 2)
    {
        for (auto& e : x[csp].sz)
        {
            if (e != csp)
            {
                mely(e, kezd);
            }else if (csp!=kezd) v.push_back(csp);
        }
    }
}

int main()
{
    cin >> n >> m;
    x.resize(n + 1);

    for (i = 1; i <= m; ++i)
    {
        cin >> a >> b;
        x[a].sz.push_back(b);
        x[b].sz.push_back(a);
    }

    for (i = 1; i <= n; ++i)
    {
        if (x[i].sz.size() == 1)
        {
            mely(x[i].sz[0], i);
        }
    }

    cout << v.size() << "\n";

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

    for (auto& e : v) cout << e << " ";

    return 0;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
base18/50
1Wrong answer0/03ms1872 KiB
2Accepted0/028ms3932 KiB
3Wrong answer0/22ms2280 KiB
4Wrong answer0/22ms2388 KiB
5Accepted2/23ms2588 KiB
6Accepted2/23ms2800 KiB
7Runtime error0/232ms64172 KiB
8Accepted2/24ms3244 KiB
9Wrong answer0/26ms3688 KiB
10Accepted2/28ms4008 KiB
11Accepted2/214ms4400 KiB
12Accepted2/214ms4400 KiB
13Runtime error0/337ms63304 KiB
14Runtime error0/337ms63068 KiB
15Runtime error0/335ms63020 KiB
16Runtime error0/332ms63008 KiB
17Runtime error0/337ms62984 KiB
18Runtime error0/348ms62964 KiB
19Wrong answer0/317ms5328 KiB
20Accepted3/328ms5860 KiB
21Wrong answer0/328ms6116 KiB
22Accepted3/328ms6216 KiB