152412025-02-17 16:17:40mateKerékpártúra (50 pont)cpp17Time limit exceeded 16/50500ms2356 KiB
#include <bits/stdc++.h>
using namespace std;

vector <vector <int>> g;
vector <bool> jart;
set <int> ans;
vector <bool> bejart;
int n,k;
bool igaz = 0;

void dfs(int p){
    if(p == k){
        igaz = 1;
        return;
    }
    jart[p] = 1;
    for(int x : g[p]){
        if(!jart[x]){
            dfs(x);
        }
    }
    if(igaz){
        bejart[p] = 1;
    }
}


int main() {
	int m; cin >> n >> m >> k;
    g.resize(n+1);
    jart.resize(n+1,0);
    bejart.resize(n+1,0);
    int a,b;
    for(int i = 0; i < m; i++){
        cin >> a >> b;
        g[a].push_back(b);
    }
    for(int i = 1; i <= n; i++){
        if(bejart[i]){
            for(int x : g[i]){
                ans.insert(x);
            }
            continue;
        }  
        jart.assign(n+1,0);
        igaz = 0;
        dfs(i);
        bejart[i] = igaz;
        if(bejart[i]){
            for(int x : g[i]){
                ans.insert(x);
            }
            //ans.insert(i);            
        } 
        
    }
    
    cout << ans.size()-1 << '\n';
    for(int x : ans){
        if(x == k)  continue;
        cout << x << ' ';
    }
}
SubtaskSumTestVerdictTimeMemory
base16/50
1Accepted0/01ms316 KiB
2Time limit exceeded0/0488ms1076 KiB
3Accepted2/21ms508 KiB
4Accepted2/21ms316 KiB
5Wrong answer0/21ms316 KiB
6Wrong answer0/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted2/23ms316 KiB
9Accepted2/27ms316 KiB
10Accepted2/212ms316 KiB
11Wrong answer0/214ms508 KiB
12Wrong answer0/237ms544 KiB
13Accepted2/282ms620 KiB
14Accepted2/2136ms680 KiB
15Wrong answer0/397ms1844 KiB
16Wrong answer0/459ms1844 KiB
17Wrong answer0/463ms2100 KiB
18Wrong answer0/359ms2116 KiB
19Wrong answer0/352ms1984 KiB
20Time limit exceeded0/3474ms2100 KiB
21Time limit exceeded0/3474ms2356 KiB
22Time limit exceeded0/3500ms2276 KiB