94742024-02-22 09:43:141478Kerékpártúra (50 pont)cpp17Elfogadva 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 << " ";  
	}


}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base50/50
1Elfogadva0/03ms2584 KiB
2Elfogadva0/020ms4284 KiB
3Elfogadva2/23ms3096 KiB
4Elfogadva2/23ms3328 KiB
5Elfogadva2/23ms3288 KiB
6Elfogadva2/23ms3260 KiB
7Elfogadva2/23ms3268 KiB
8Elfogadva2/24ms3400 KiB
9Elfogadva2/24ms3668 KiB
10Elfogadva2/26ms3768 KiB
11Elfogadva2/27ms3820 KiB
12Elfogadva2/214ms4456 KiB
13Elfogadva2/213ms4540 KiB
14Elfogadva2/221ms5056 KiB
15Elfogadva3/335ms5968 KiB
16Elfogadva4/439ms6104 KiB
17Elfogadva4/454ms7304 KiB
18Elfogadva3/348ms7468 KiB
19Elfogadva3/341ms7244 KiB
20Elfogadva3/3115ms8896 KiB
21Elfogadva3/3129ms9940 KiB
22Elfogadva3/3130ms10568 KiB