181682025-10-08 16:15:47KristófKerékpártúra (50 pont)cpp17Accepted 50/50150ms4152 KiB
#include <iostream>
#include <bits/stdc++.h>

using namespace std;

set<int> halmaz;


void DFS(vector<vector<int>> &graf,int v,vector<bool> &latogatas)
{
latogatas[v]=true;
for(int i=0;i<graf[v].size();i++)
    {
    halmaz.insert(graf[v][i]);
    if(!latogatas[graf[v][i]])
        DFS(graf,graf[v][i],latogatas);
    }

}


int main()
{
    //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,m,k;
    cin>>n>>m>>k;
    vector<vector<int>> graf(n+1);
    vector<vector<int>> inverzgraf(n+1);
    int x,y;
    for(int i=0;i<m;i++)
        {
        cin>>x>>y;
        graf[x].push_back(y);
        inverzgraf[y].push_back(x);
        }
    vector<bool> latogatas(n+1,false);
    DFS(inverzgraf,k,latogatas);
    set<int> halmaz2=halmaz;
    for(auto x : halmaz)
        {
        for(auto y : graf[x])
            {
            halmaz2.insert(y);
            }
        }
    halmaz2.erase(k);
    cout<<halmaz2.size()<<endl;
    for(auto x : halmaz2)
        {
        cout<<x<<" ";
        }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/01ms512 KiB
2Accepted0/019ms1332 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/21ms500 KiB
6Accepted2/21ms596 KiB
7Accepted2/21ms316 KiB
8Accepted2/23ms316 KiB
9Accepted2/23ms468 KiB
10Accepted2/24ms424 KiB
11Accepted2/24ms564 KiB
12Accepted2/212ms732 KiB
13Accepted2/210ms680 KiB
14Accepted2/220ms936 KiB
15Accepted3/335ms1844 KiB
16Accepted4/441ms2296 KiB
17Accepted4/459ms2724 KiB
18Accepted3/350ms2876 KiB
19Accepted3/346ms2868 KiB
20Accepted3/3127ms3216 KiB
21Accepted3/3146ms3700 KiB
22Accepted3/3150ms4152 KiB