57752023-09-27 07:34:12zsebiElágazás nélküli úton levő települések (50 pont)cpp11Wrong answer 6/5030ms7560 KiB
// elagazas nelkul.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <queue>
#include <algorithm>

#define ll long long 
using namespace std;

struct adat
{
    bool lat = false;
    vector<ll>sz;
};
ll n, m;

int main()
{
    cin >> n >> m;
    vector<adat>x(n+1);
    vector<ll>ans;
    for (int i = 1; i <= m; ++i)
    {
        ll a, b;
        cin >> a >> b;
        x[a].sz.push_back(b);
        x[b].sz.push_back(a);
    }
    vector<ll>volt;
    for (int i=1;i<=n;++i)
    {
        if (x[i].sz.size() == 1)
        {
            deque<ll>v;
            v.push_back(i);
            
            while (!v.empty())
            {
                ll akt = v.front();
                volt.push_back(akt);
                v.pop_front();
                x[akt].lat = true;
                for (auto& e : x[akt].sz)
                {
                    auto res = find(volt.begin(), volt.end(), e);
                    if (res == end(volt))
                    {
                        if (!x[e].lat)
                        {

                            ans.push_back(e);
                            x[e].lat = true;
                        }

                        if (x[e].sz.size() <= 2  )
                        {
                            
                            v.push_back(e);
                        }
                    }
                }

            }
            volt.clear();
        }
    }
    cout << ans.size() << "\n";
    for (auto& e : ans)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
base6/50
1Accepted0/03ms1812 KiB
2Wrong answer0/030ms4964 KiB
3Wrong answer0/23ms2492 KiB
4Accepted2/22ms2448 KiB
5Accepted2/22ms2528 KiB
6Wrong answer0/22ms2544 KiB
7Wrong answer0/22ms2636 KiB
8Wrong answer0/24ms2880 KiB
9Wrong answer0/26ms3272 KiB
10Wrong answer0/29ms3608 KiB
11Accepted2/216ms4696 KiB
12Wrong answer0/216ms4624 KiB
13Wrong answer0/34ms3700 KiB
14Wrong answer0/34ms4016 KiB
15Wrong answer0/36ms4220 KiB
16Wrong answer0/37ms4608 KiB
17Wrong answer0/314ms5472 KiB
18Wrong answer0/314ms5688 KiB
19Wrong answer0/317ms6316 KiB
20Wrong answer0/329ms7068 KiB
21Wrong answer0/330ms7544 KiB
22Wrong answer0/329ms7560 KiB