57732023-09-26 10:33:54zsebiElágazás nélküli úton levő települések (50 pont)cpp11Wrong answer 4/5030ms6948 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();
                for (auto& e : x[akt].sz)
                {
                    auto res = find(volt.begin(), volt.end(), e);
                    if (res == end(volt))
                    {
                        ans.push_back(e);
                        if (x[e].sz.size() <= 2 && !x[e].lat)
                        {
                            x[e].lat = true;
                            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
base4/50
1Accepted0/03ms1812 KiB
2Wrong answer0/030ms4916 KiB
3Wrong answer0/23ms2492 KiB
4Wrong answer0/22ms2564 KiB
5Accepted2/22ms2660 KiB
6Wrong answer0/23ms2868 KiB
7Wrong answer0/22ms2952 KiB
8Wrong answer0/24ms3212 KiB
9Wrong answer0/27ms3704 KiB
10Wrong answer0/28ms3984 KiB
11Accepted2/216ms4648 KiB
12Wrong answer0/216ms4532 KiB
13Wrong answer0/34ms3528 KiB
14Wrong answer0/34ms3772 KiB
15Wrong answer0/36ms3960 KiB
16Wrong answer0/37ms4364 KiB
17Wrong answer0/314ms4960 KiB
18Wrong answer0/314ms5212 KiB
19Wrong answer0/317ms5688 KiB
20Wrong answer0/329ms6640 KiB
21Wrong answer0/330ms6944 KiB
22Wrong answer0/330ms6948 KiB