208722026-01-10 17:56:57gkataElágazás nélküli úton levő települések (50 pont)cpp17Hibás válasz 31/5014ms1844 KiB
// zsakfalvak.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
{
    int lat;
    vector<ll>sz;
};

vector<adat>x;
deque<ll>v1, v2, ans;

ll n, a, b, m, i, akt, kezd;
bool ok = false;

int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);

    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)
        {
            v1.push_back(i);
        }
    }

        while (!v1.empty())
        {
            kezd = v1.front();
            v1.pop_front();
            
            v2.push_back(kezd);
            x[kezd].lat = 1;

            while (!v2.empty())
            {
                akt = v2.front();
                v2.pop_front();

                if (akt != kezd) ans.push_back(akt);

                for (auto& e : x[akt].sz)
                {
                    //cout << e << " ";
                    if (!x[e].lat && x[akt].sz.size()<=2)
                    {
                        x[e].lat = 1;
                        v2.push_back(e);
                    }
                }
            }
        }

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

        cout << ans.size() << endl;
        for (auto& e : ans) cout << e << " ";

}

/*
8 9
1 2
1 6
2 7
1 5
3 4
4 5
5 6
6 7
8 7
*/
// 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ÖsszpontTesztVerdiktIdőMemória
base31/50
1Elfogadva0/01ms512 KiB
2Elfogadva0/014ms1844 KiB
3Hibás válasz0/21ms316 KiB
4Elfogadva2/21ms316 KiB
5Elfogadva2/21ms316 KiB
6Hibás válasz0/21ms508 KiB
7Elfogadva2/21ms316 KiB
8Elfogadva2/22ms316 KiB
9Elfogadva2/23ms564 KiB
10Elfogadva2/24ms564 KiB
11Elfogadva2/27ms1076 KiB
12Elfogadva2/27ms1084 KiB
13Elfogadva3/32ms316 KiB
14Hibás válasz0/33ms564 KiB
15Hibás válasz0/33ms564 KiB
16Hibás válasz0/34ms564 KiB
17Hibás válasz0/37ms1096 KiB
18Hibás válasz0/37ms1076 KiB
19Elfogadva3/38ms1332 KiB
20Elfogadva3/313ms1816 KiB
21Elfogadva3/314ms1768 KiB
22Elfogadva3/313ms1844 KiB