152402025-02-17 14:31:36mateKerékpártúra (50 pont)cpp17Time limit exceeded 20/50500ms2264 KiB
#include <bits/stdc++.h>
using namespace std;

vector <vector <int>> g;
vector <bool> jart;
set <int> ans;
vector <bool> bejart;
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() {
	int m,k; 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(i == k)  continue;
        jart.assign(n+1,0);
        bejart[i] = bfs(i,k);
        if(bejart[i]){
            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/0479ms820 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms508 KiB
5Accepted2/21ms316 KiB
6Accepted2/21ms316 KiB
7Accepted2/22ms316 KiB
8Accepted2/223ms432 KiB
9Accepted2/264ms316 KiB
10Accepted2/2109ms456 KiB
11Accepted2/2289ms484 KiB
12Accepted2/2219ms564 KiB
13Time limit exceeded0/2479ms564 KiB
14Time limit exceeded0/2483ms548 KiB
15Time limit exceeded0/3500ms1084 KiB
16Time limit exceeded0/4485ms1076 KiB
17Time limit exceeded0/4483ms1076 KiB
18Time limit exceeded0/3490ms1076 KiB
19Time limit exceeded0/3500ms1076 KiB
20Time limit exceeded0/3493ms2088 KiB
21Time limit exceeded0/3472ms2244 KiB
22Time limit exceeded0/3486ms2264 KiB