96992024-03-01 12:00:37tamasmarkKerékpártúra (50 pont)cpp17Time limit exceeded 44/50500ms12616 KiB
// kerekpartura.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <deque>
#include <set>
using namespace std;
struct adat
{
    bool lat,mlat;
    vector<int>szbe;
    vector<int>sztol;
};
vector<adat>x;
deque<int>v;
int n, m, i, j, a, b,kezd;
set<int>megold;
vector<int>jo;
void melysegi(int csp)
{
    x[csp].mlat = true;
    for (auto& e : x[csp].sztol)
    {
        if (!x[e].mlat) melysegi(e);
    }
}
int main()
{
    cin >> n >> m >> kezd;
    x.resize(n + 1);
    for (i = 1; i <= m; ++i)
    {
        cin >> a >> b;
        x[a].sztol.push_back(b);
        x[b].szbe.push_back(a);
    }
    jo.push_back(kezd);
    v.push_back(kezd);
    x[kezd].lat = true;
    x[kezd].mlat = true;
    melysegi(kezd);
    while (!v.empty())
    {
        int akt = v.front();
        v.pop_front();
        x[akt].lat = true;
        for (auto& e : x[akt].szbe)
        {
            if (!x[e].lat)
            {
                v.push_back(e);
                jo.push_back(e);
            }
        }
    }
    for (auto& e:jo)
    {
        for (auto& f : x[e].sztol)
        {
            if (x[f].mlat == true&&f!=kezd) megold.insert(f);
        }
    }
    cout << megold.size() << "\n";
    for (auto& e : megold) cout << e<<" ";
    return 0;
}
/*
8 16 2
1 3
2 1
2 5
5 4
5 1
5 6
4 3
4 7
4 1
3 8
3 7
6 2
6 4
6 7
7 8
8 3

*/
// 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
base44/50
1Accepted0/03ms1816 KiB
2Accepted0/028ms4524 KiB
3Accepted2/23ms2192 KiB
4Accepted2/23ms2404 KiB
5Accepted2/23ms2492 KiB
6Accepted2/23ms2712 KiB
7Accepted2/23ms2760 KiB
8Accepted2/24ms3064 KiB
9Accepted2/24ms3176 KiB
10Accepted2/24ms3488 KiB
11Accepted2/27ms3568 KiB
12Accepted2/213ms3852 KiB
13Accepted2/221ms4180 KiB
14Accepted2/237ms5248 KiB
15Accepted3/337ms7224 KiB
16Accepted4/441ms7520 KiB
17Accepted4/457ms8664 KiB
18Accepted3/352ms8468 KiB
19Accepted3/346ms8640 KiB
20Time limit exceeded0/3500ms7164 KiB
21Time limit exceeded0/3433ms12460 KiB
22Accepted3/3331ms12616 KiB