136172025-01-08 11:25:40NotYouKerékpártúra (50 pont)cpp17Wrong answer 21/50129ms3516 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.pop_back();
        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.pop_back();
        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
SubtaskSumTestVerdictTimeMemory
base21/50
1Wrong answer0/01ms316 KiB
2Accepted0/019ms1336 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Wrong answer0/21ms316 KiB
6Accepted2/21ms316 KiB
7Wrong answer0/21ms316 KiB
8Accepted2/23ms428 KiB
9Accepted2/23ms508 KiB
10Accepted2/24ms316 KiB
11Wrong answer0/24ms456 KiB
12Accepted2/212ms564 KiB
13Accepted2/210ms524 KiB
14Accepted2/221ms852 KiB
15Wrong answer0/334ms1560 KiB
16Wrong answer0/435ms1756 KiB
17Wrong answer0/450ms2100 KiB
18Wrong answer0/345ms1820 KiB
19Wrong answer0/339ms1844 KiB
20Accepted3/3119ms3124 KiB
21Wrong answer0/3128ms3436 KiB
22Wrong answer0/3129ms3516 KiB