3979 2023. 03. 07 12:48:00 bzsofia Elágazás nélküli úton levő települések (50 pont) cpp11 Hibás válasz 25/50 28ms 6132 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;
    int tav;
    vector <int> sz;
};

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

void mely(int csp, int kezd)
{
    x[csp].lat = 1;
    v.push_back(csp);

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

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
Részfeladat Összpont Teszt Verdikt Idő Memória
base 25/50
1 Elfogadva 0/0 3ms 1880 KiB
2 Elfogadva 0/0 28ms 3984 KiB
3 Hibás válasz 0/2 3ms 2324 KiB
4 Hibás válasz 0/2 3ms 2572 KiB
5 Elfogadva 2/2 3ms 2788 KiB
6 Elfogadva 2/2 2ms 2876 KiB
7 Elfogadva 2/2 3ms 2996 KiB
8 Elfogadva 2/2 4ms 3460 KiB
9 Elfogadva 2/2 6ms 3888 KiB
10 Elfogadva 2/2 8ms 4000 KiB
11 Elfogadva 2/2 14ms 4360 KiB
12 Elfogadva 2/2 14ms 4312 KiB
13 Hibás válasz 0/3 4ms 3872 KiB
14 Hibás válasz 0/3 4ms 4116 KiB
15 Hibás válasz 0/3 6ms 4516 KiB
16 Hibás válasz 0/3 6ms 4548 KiB
17 Hibás válasz 0/3 13ms 5148 KiB
18 Hibás válasz 0/3 14ms 5240 KiB
19 Hibás válasz 0/3 17ms 5492 KiB
20 Elfogadva 3/3 28ms 6008 KiB
21 Elfogadva 3/3 28ms 6008 KiB
22 Elfogadva 3/3 28ms 6132 KiB