208652026-01-10 17:09:11gkataElágazás nélküli úton levő települések (50 pont)cpp17Hibás válasz 20/5014ms1848 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, el;
    vector<ll>sz;
};

vector<adat>x;
deque<ll>v, ans;

ll n, a, b, m, i, akt, db;
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)
        {
            v.push_back(i);
            x[i].el = 1;
        }
    }

   // for (auto& e : v) cout << e << " ";

    if (v.empty()) cout << 0;
    else
    {
        x[v.front()].lat = 1;
        //x[v.front()].lep = 0;

        while (!v.empty())
        {
            akt = v.front();
            v.pop_front();
            db = 0;

            for (auto& e : x[akt].sz) if (!x[e].lat) ++db;
            for (auto& e : x[akt].sz)
            {
                //cout << e << " ";
                if (!x[e].lat && db == 1)
                {
                    x[e].lat = 1;
                    if (x[akt].el==1)
                    {
                        x[e].el = 1;
                        ans.push_back(e);
                        v.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
base20/50
1Elfogadva0/01ms500 KiB
2Elfogadva0/014ms1844 KiB
3Hibás válasz0/21ms316 KiB
4Elfogadva2/21ms316 KiB
5Elfogadva2/21ms316 KiB
6Elfogadva2/21ms316 KiB
7Hibás válasz0/21ms316 KiB
8Elfogadva2/22ms316 KiB
9Hibás válasz0/23ms520 KiB
10Elfogadva2/24ms564 KiB
11Elfogadva2/27ms1076 KiB
12Elfogadva2/27ms1136 KiB
13Hibás válasz0/32ms508 KiB
14Hibás válasz0/32ms564 KiB
15Hibás válasz0/33ms564 KiB
16Hibás válasz0/33ms636 KiB
17Hibás válasz0/36ms1076 KiB
18Hibás válasz0/37ms1092 KiB
19Hibás válasz0/38ms1268 KiB
20Elfogadva3/313ms1848 KiB
21Hibás válasz0/314ms1712 KiB
22Elfogadva3/314ms1780 KiB