100802024-03-26 16:53:16VargusElágazás nélküli úton levő települések (50 pont)cpp17Wrong answer 25/50112ms9652 KiB
#include <iostream>
#include <queue>
#include <algorithm>
#define ll long long

using namespace std;

struct adat
{
    bool lat = false;
    vector <ll> sz;
};
vector <adat> x;
deque <ll> poz;

ll p = 0;
void ell(ll csp)
{
    x[csp].lat = true;
    ll db = 0;
    for (auto& e : x[csp].sz)
    {
        if (!x[e].lat)
        {
            ++db;
            p = e;
        }
    }
    if (db == 1)
    {
        x[p].lat = true;
        poz.push_back(p);
        ell(p);
    }
}

void melyseg(ll csp)
{
    if (x[csp].sz.size() > 1)
        return;
    else
    {
        ell(csp);
    }
}

int main()
{
    ll n, m, i;
    cin >> n >> m;
    x.resize(n + 1);
    for (i = 1; i <= m; ++i)
    {
        ll cs1, cs2;
        cin >> cs1 >> cs2;
        x[cs1].sz.push_back(cs2);
        x[cs2].sz.push_back(cs1);
    }
    for (ll i = 1; i <= n; ++i)
    {
        for (ll j = 1; j <= n; ++j)
            x[j].lat = false;
        melyseg(i);
    }
    cout << poz.size() << "\n";
    sort(poz.begin(), poz.end());
    for (auto& e : poz)
        cout << e << " ";

    return 0;
}

SubtaskSumTestVerdictTimeMemory
base25/50
1Accepted0/03ms1956 KiB
2Accepted0/0112ms5256 KiB
3Wrong answer0/23ms2568 KiB
4Wrong answer0/22ms2664 KiB
5Accepted2/23ms2900 KiB
6Accepted2/22ms2880 KiB
7Accepted2/23ms3128 KiB
8Accepted2/24ms3728 KiB
9Accepted2/29ms4224 KiB
10Accepted2/217ms4504 KiB
11Accepted2/229ms5460 KiB
12Accepted2/235ms5900 KiB
13Wrong answer0/34ms4900 KiB
14Wrong answer0/38ms5076 KiB
15Wrong answer0/314ms5184 KiB
16Wrong answer0/327ms5284 KiB
17Wrong answer0/352ms6200 KiB
18Wrong answer0/365ms6508 KiB
19Wrong answer0/379ms7212 KiB
20Accepted3/393ms8340 KiB
21Accepted3/3108ms9076 KiB
22Accepted3/3111ms9652 KiB