136302025-01-08 11:41:33NotYouKerékpártúra (50 pont)cpp17Elfogadva 50/50142ms3796 KiB
// kerekpar.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <vector>
#include <iostream>
#include<set>
using namespace std;

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    int hn, hv;
    vector<vector<int>>graf(n + 1, vector<int>(0));
    vector<vector<int>>graf2(n + 1, vector<int>(0));

    for (int i = 0; i < m; i++) {
        cin >> hn >> hv;
        graf[hn].push_back(hv);
        graf2[hv].push_back(hn);
    }
    vector<bool>h(n + 1);
    vector<char>szin(n + 1, 'W');
    h[k] = true;
    vector<int>q;
    q.push_back(k);
    while (q.size() != 0) {
        int p = q[0];
        q.erase(q.begin());
        szin[p] = 'G';
        for (size_t i = 0; i < graf[p].size(); i++) {
            if (szin[graf[p][i]] == 'W') {
                q.push_back(graf[p][i]);
                szin[graf[p][i]] = 'G';
            }
        }
    }
    q.push_back(k);
    while (q.size() != 0) {
        int p = q[0];
        q.erase(q.begin());
        szin[p] = 'B';
        for (size_t i = 0; i < graf2[p].size(); i++) {
            if (szin[graf2[p][i]] == 'G') {
                q.push_back(graf2[p][i]);
                szin[graf2[p][i]] = 'B';
                h[graf2[p][i]] = true;
            }
        }
    }
    int szamlalo = 0;
    string sor = "";
    set <int> megold;
    for (int i = 0; i < n + 1; i++) {
        if (h[i] == true) {
            szamlalo++;
            megold.insert(i);
            for (int x : graf[i]) {
                szamlalo++;
                megold.insert(x);
            }
        }
    }
    if (megold.size() > 0) {
        cout << megold.size() - 1 << endl;
        for (int i : megold) {
            if (i != k)cout << i << " ";
        }
    }
    else
    {
        cout << "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
RészfeladatÖsszpontTesztVerdiktIdőMemória
base50/50
1Elfogadva0/01ms316 KiB
2Elfogadva0/020ms1332 KiB
3Elfogadva2/21ms316 KiB
4Elfogadva2/21ms316 KiB
5Elfogadva2/21ms316 KiB
6Elfogadva2/21ms316 KiB
7Elfogadva2/21ms404 KiB
8Elfogadva2/23ms508 KiB
9Elfogadva2/23ms612 KiB
10Elfogadva2/23ms316 KiB
11Elfogadva2/24ms564 KiB
12Elfogadva2/212ms620 KiB
13Elfogadva2/210ms832 KiB
14Elfogadva2/220ms888 KiB
15Elfogadva3/337ms1952 KiB
16Elfogadva4/439ms2100 KiB
17Elfogadva4/456ms2356 KiB
18Elfogadva3/350ms2356 KiB
19Elfogadva3/345ms2356 KiB
20Elfogadva3/3119ms3328 KiB
21Elfogadva3/3137ms3588 KiB
22Elfogadva3/3142ms3796 KiB