85662024-01-22 07:19:56bzsofiaKerékpártúra (50 pont)cpp14Accepted 50/5059ms14684 KiB
// Proba.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
//#include <fstream>
#include <vector>
#include <queue>

#define ll long long

using namespace std;

//ifstream fin("kerekpar.in");
//ofstream fout("kerekpar.out");

struct adat {
    bool lat;
    vector <ll> sz;
};

ll i, n, m, a, b, kezd, akt;
vector <ll> v;
queue <ll> s;

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

    cin >> n >> m >> kezd;
    vector <adat> oda(n + 1);
    vector <adat> vissza(n + 1);

    for (i = 1; i <= m; ++i)
    {
        cin >> a >> b;
        oda[a].sz.push_back(b);
        vissza[b].sz.push_back(a);
    }

    vissza[kezd].lat = 1;
    s.push(kezd);
    while (!s.empty())
    {
        akt = s.front();
        s.pop();
        for (auto& e : vissza[akt].sz)
        {
            if (!vissza[e].lat)
            {
                s.push(e);
                vissza[e].lat = 1;
            }
        }
    }

    oda[kezd].lat = 1;
    s.push(kezd);
    while (!s.empty())
    {
        akt = s.front();
        //cout << akt << " ";
        s.pop();
        for (auto& e : oda[akt].sz)
        {
            if (!oda[e].lat)
            {
                v.push_back(e);
                oda[e].lat = 1;
                if (vissza[e].lat) s.push(e);
            }
        }
    }

    cout << v.size()<<"\n";
    if (!v.empty())
    {
        for (auto& e : v)
        {
            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
base50/50
1Accepted0/03ms2104 KiB
2Accepted0/012ms5224 KiB
3Accepted2/23ms2364 KiB
4Accepted2/23ms2644 KiB
5Accepted2/23ms2800 KiB
6Accepted2/23ms2780 KiB
7Accepted2/23ms2728 KiB
8Accepted2/23ms3024 KiB
9Accepted2/24ms3028 KiB
10Accepted2/24ms3352 KiB
11Accepted2/24ms3288 KiB
12Accepted2/28ms4040 KiB
13Accepted2/27ms3868 KiB
14Accepted2/212ms4920 KiB
15Accepted3/319ms7012 KiB
16Accepted4/420ms7624 KiB
17Accepted4/428ms8628 KiB
18Accepted3/326ms8104 KiB
19Accepted3/321ms7596 KiB
20Accepted3/352ms13484 KiB
21Accepted3/359ms14356 KiB
22Accepted3/359ms14684 KiB