152442025-02-17 16:24:38mateKerékpártúra (50 pont)cpp17Time limit exceeded 20/50488ms2276 KiB
#include <bits/stdc++.h>
using namespace std;

vector <vector <int>> g;
vector <bool> jart;
set <int> ans;
int n;

bool bfs(int p, int k){
    jart[p] = 1;
    queue <int> q;
    q.push(p);
    while(!q.empty()){
        int csucs = q.front();
        q.pop();
        if(csucs == k)  return 1;
        jart[csucs] = 1;
        for(int x : g[csucs]){
            if(jart[x]) continue;
            q.push(x);
        }
    }
    return 0;
}





int main() {
    ios::sync_with_stdio(0); cin.tie(0);
	int m,k; cin >> n >> m >> k;
    bool igaz = 0;
    g.resize(n+1);
    jart.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(i == k)  continue;
        jart.assign(n+1,0);
        igaz = bfs(i,k);
        if(igaz){
            for(int x : g[i]){
                ans.insert(x);
            }
            
        } 
    }
    
    cout << ans.size()-1 << '\n';
    for(int x : ans){
        if(x == k)  continue;
        cout << x << ' ';
    }
}
SubtaskSumTestVerdictTimeMemory
base20/50
1Accepted0/01ms316 KiB
2Time limit exceeded0/0486ms820 KiB
3Accepted2/21ms508 KiB
4Accepted2/21ms316 KiB
5Accepted2/21ms368 KiB
6Accepted2/21ms316 KiB
7Accepted2/22ms316 KiB
8Accepted2/221ms460 KiB
9Accepted2/263ms464 KiB
10Accepted2/2108ms476 KiB
11Accepted2/2287ms316 KiB
12Accepted2/2214ms564 KiB
13Time limit exceeded0/2479ms564 KiB
14Time limit exceeded0/2481ms564 KiB
15Time limit exceeded0/3483ms1076 KiB
16Time limit exceeded0/4481ms1076 KiB
17Time limit exceeded0/4488ms1332 KiB
18Time limit exceeded0/3481ms1076 KiB
19Time limit exceeded0/3483ms1076 KiB
20Time limit exceeded0/3477ms2096 KiB
21Time limit exceeded0/3488ms2256 KiB
22Time limit exceeded0/3479ms2276 KiB