181672025-10-08 16:03:51KristófKerékpártúra (50 pont)cpp17Accepted 50/5078ms6124 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/01ms316 KiB
2Accepted0/09ms1588 KiB
3Accepted2/21ms500 KiB
4Accepted2/21ms316 KiB
5Accepted2/21ms316 KiB
6Accepted2/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted2/22ms316 KiB
9Accepted2/22ms316 KiB
10Accepted2/22ms512 KiB
11Accepted2/23ms564 KiB
12Accepted2/26ms824 KiB
13Accepted2/26ms820 KiB
14Accepted2/29ms1064 KiB
15Accepted3/317ms2296 KiB
16Accepted4/419ms2880 KiB
17Accepted4/429ms3364 KiB
18Accepted3/327ms3404 KiB
19Accepted3/325ms3328 KiB
20Accepted3/359ms4816 KiB
21Accepted3/372ms5796 KiB
22Accepted3/378ms6124 KiB