57722023-09-25 09:51:06zsebiElágazás nélküli úton levő települések (50 pont)cpp11Wrong answer 4/5029ms7120 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
{
    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)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/03ms1680 KiB
2Wrong answer0/029ms4408 KiB
3Wrong answer0/23ms2380 KiB
4Wrong answer0/23ms2340 KiB
5Accepted2/23ms2552 KiB
6Wrong answer0/23ms2764 KiB
7Wrong answer0/23ms2932 KiB
8Wrong answer0/24ms3376 KiB
9Wrong answer0/26ms3572 KiB
10Wrong answer0/29ms3968 KiB
11Accepted2/216ms4664 KiB
12Wrong answer0/216ms4788 KiB
13Wrong answer0/34ms3780 KiB
14Wrong answer0/34ms4188 KiB
15Wrong answer0/36ms4456 KiB
16Wrong answer0/36ms4616 KiB
17Wrong answer0/314ms5392 KiB
18Wrong answer0/314ms5480 KiB
19Wrong answer0/317ms5996 KiB
20Wrong answer0/328ms6776 KiB
21Wrong answer0/329ms7120 KiB
22Wrong answer0/329ms6948 KiB