94742024-02-22 09:43:141478Kerékpártúra (50 pont)cpp17Accepted 50/50130ms10568 KiB
#include <bits/stdc++.h>  
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
double eps = 1e-12;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
ll MOD = 1e9 + 7;

int N_MAX = 1e4;
vector<vector<int>> e1(N_MAX + 1), e2(N_MAX + 1);
vector<bool> reachK(N_MAX + 1);
vector<bool> visited(N_MAX + 1);
vector<int> ans;

int n, m, k;

void dfs(int x){
	reachK[x] = 1;
	for(int i = 0; i < e2[x].size(); i++){
		if(!reachK[e2[x][i]]){
			dfs(e2[x][i]);
		}
	}
}

void dfs2(int x){
	visited[x] = 1;
	if(x != k) ans.push_back(x);
	for(int i = 0; i < e1[x].size(); i++){
		if(!visited[e1[x][i]] && (reachK[e1[x][i]] || reachK[x])){
			dfs2(e1[x][i]);
		}
	}
}


int main()
{
	//ifstream cin("in.txt");

	cin >> n >> m >> k;

	for(int i = 1; i <= m; i++){
		int a, b;
		cin >> a >> b;
		e1[a].push_back(b);
		e2[b].push_back(a);
	}

	dfs(k);
	dfs2(k);
	

	cout << ans.size() << '\n';
	for(int a:ans){
		cout << a << " ";  
	}


}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms2584 KiB
2Accepted0/020ms4284 KiB
3Accepted2/23ms3096 KiB
4Accepted2/23ms3328 KiB
5Accepted2/23ms3288 KiB
6Accepted2/23ms3260 KiB
7Accepted2/23ms3268 KiB
8Accepted2/24ms3400 KiB
9Accepted2/24ms3668 KiB
10Accepted2/26ms3768 KiB
11Accepted2/27ms3820 KiB
12Accepted2/214ms4456 KiB
13Accepted2/213ms4540 KiB
14Accepted2/221ms5056 KiB
15Accepted3/335ms5968 KiB
16Accepted4/439ms6104 KiB
17Accepted4/454ms7304 KiB
18Accepted3/348ms7468 KiB
19Accepted3/341ms7244 KiB
20Accepted3/3115ms8896 KiB
21Accepted3/3129ms9940 KiB
22Accepted3/3130ms10568 KiB