136082025-01-08 11:21:10NotYouKerékpártúra (50 pont)cpp17Wrong answer 44/50123ms3608 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 < graf2[p].size(); i++) {
            if (szin[graf2[p][i]] == 'W') {
                q.push_back(graf2[p][i]);
                szin[graf2[p][i]] = 'G';
                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
base44/50
1Accepted0/01ms316 KiB
2Accepted0/019ms1332 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/21ms380 KiB
6Accepted2/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted2/23ms512 KiB
9Accepted2/23ms316 KiB
10Accepted2/24ms500 KiB
11Accepted2/24ms564 KiB
12Accepted2/212ms656 KiB
13Accepted2/210ms564 KiB
14Accepted2/219ms852 KiB
15Accepted3/334ms1904 KiB
16Accepted4/437ms2100 KiB
17Accepted4/454ms2492 KiB
18Accepted3/348ms2360 KiB
19Accepted3/343ms2312 KiB
20Accepted3/3114ms3124 KiB
21Wrong answer0/3123ms3384 KiB
22Wrong answer0/3123ms3608 KiB