82502024-01-13 20:21:52sangerafKerékpártúra (50 pont)cpp17Accepted 50/50138ms10760 KiB
#include<bits/stdc++.h>
using namespace std;

vector<vector<int>> g, gr;
vector<bool> vis, visr;
vector<bool> ans;

void dfs(int v){
    vis[v] = true;
    for(int x : g[v]){
        if(!vis[x]) dfs(x);
    }
}

void dfsr(int v){
    visr[v] = true;
    for(int x : gr[v]){
        if(!visr[x]) dfsr(x);
    }
}

int main(){
    int n, m, k; cin >> n >> m >> k;
    g.resize(n+1);
    gr.resize(n+1);
    for(int i=0; i<m; i++){
        int u, v; cin >> u >> v;
        g[u].push_back(v);
        gr[v].push_back(u);
    }
    vis.resize(n+1, 0);
    dfs(k);
    visr.resize(n+1, 0);
    dfsr(k);
    //for(bool x : vis) cout << x << " "; cout << endl;
    //for(bool x : visr) cout << x << " "; cout << endl;
    ans.resize(n+1, 0);
    for(int i=1; i<=n; i++){
        if(vis[i] && visr[i]){
            ans[i] = true;
            for(int x : g[i]){
                ans[x] = true;
            }
        }
    }
    ans[k]=false;
    int db=0;
    for(bool x : ans) if(x) db++;
    cout << db << endl;
    for(int i=1; i<=n; i++){
        if(ans[i]) cout << i << " ";
    }
    cout << endl;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms2148 KiB
2Accepted0/023ms4764 KiB
3Accepted2/23ms2660 KiB
4Accepted2/23ms2616 KiB
5Accepted2/23ms2772 KiB
6Accepted2/23ms2840 KiB
7Accepted2/23ms2968 KiB
8Accepted2/24ms3108 KiB
9Accepted2/24ms3372 KiB
10Accepted2/24ms3352 KiB
11Accepted2/27ms3692 KiB
12Accepted2/214ms4296 KiB
13Accepted2/213ms4264 KiB
14Accepted2/224ms4796 KiB
15Accepted3/337ms6568 KiB
16Accepted4/441ms6972 KiB
17Accepted4/457ms7860 KiB
18Accepted3/350ms7936 KiB
19Accepted3/343ms7628 KiB
20Accepted3/3128ms10500 KiB
21Accepted3/3138ms10628 KiB
22Accepted3/3138ms10760 KiB