99132024-03-18 15:42:30VargusKerékpártúra (50 pont)cpp17Wrong answer 46/50135ms10688 KiB
#include <iostream>
#include <queue>
#include <set>
#define ll long long

using namespace std;

struct adat
{
    bool lat = false, utak = false;
    ll honnan = 0;
    vector <ll> sz;
};
vector <adat> x;
deque <ll> vissza;
set <ll> ut;

ll kezd;
void melyseg(ll csp)
{
    x[csp].lat = true;
    for (auto& e : x[csp].sz)
    {
        if (csp == kezd)
            ut.insert(e);
        if (!x[e].lat)
        { 
            x[e].honnan = csp;
            melyseg(e);
        }
        if (e == kezd)
            vissza.push_front(csp);
    }
}

int main()
{
    ll csp, el;
    cin >> csp >> el >> kezd;
    x.resize(csp + 1);
    for (ll i = 1; i <= el; ++i)
    {
        ll cs1, cs2;
        cin >> cs1 >> cs2;
        x[cs1].sz.push_back(cs2);

    }
    melyseg(kezd);

    ll akt = 0;
    x[kezd].utak = true;
    while (!vissza.empty())
    {
        akt = vissza.front();
        vissza.pop_front();
        x[akt].utak = true;
        while (akt != kezd)
        {
            ut.insert(akt);
            for (auto& f : x[akt].sz)
            {
                if (!x[f].utak)
                {
                    x[f].utak = true;
                    ut.insert(f);
                }
            }
            akt = x[akt].honnan;
        }
    }
    cout << ut.size() << endl;
    for (auto& e : ut)
        cout << e << " ";

    return 0;
}

SubtaskSumTestVerdictTimeMemory
base46/50
1Accepted0/03ms1680 KiB
2Accepted0/020ms3840 KiB
3Wrong answer0/23ms2064 KiB
4Accepted2/23ms2268 KiB
5Accepted2/23ms2484 KiB
6Accepted2/23ms2608 KiB
7Accepted2/23ms2744 KiB
8Accepted2/24ms3012 KiB
9Wrong answer0/24ms3192 KiB
10Accepted2/24ms3408 KiB
11Accepted2/26ms3832 KiB
12Accepted2/213ms4148 KiB
13Accepted2/213ms4276 KiB
14Accepted2/221ms4720 KiB
15Accepted3/335ms7056 KiB
16Accepted4/437ms7600 KiB
17Accepted4/452ms8764 KiB
18Accepted3/348ms8348 KiB
19Accepted3/343ms8180 KiB
20Accepted3/3125ms10184 KiB
21Accepted3/3131ms10536 KiB
22Accepted3/3135ms10688 KiB