82652024-01-13 21:42:20bovizdbKerékpártúra (50 pont)cpp17Accepted 50/5059ms15812 KiB
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long
#define endl "\n"
#define pll pair<ll, ll>
#define fs first
#define sc second
#define vll vector<ll>
#define v2d vector<vector<ll>>
#define vpll vector<pll>
#define qll queue<ll>
#define stll stack<ll>
#define sll set<ll>
#define mll map<ll, ll>

ll n, m, k;
v2d g, gcomp;

void solve()
{
    cin >> n >> m >> k;
    g.resize(n);
    gcomp.resize(n);
    for (ll i = 0; i < m; i++)
    {
        ll in1, in2;
        cin >> in1 >> in2;
        g[in1-1].push_back(in2-1);
        gcomp[in2-1].push_back(in1-1);
    }
    vll v;
    qll q;
    q.push(k-1);
    vll c(n, 0);
    while(!q.empty())
    {
        ll p = q.front();
        v.push_back(p);
        for (ll j = 0; j < gcomp[p].size(); j++)
        {
            if (c[gcomp[p][j]] == 0)
            {
                q.push(gcomp[p][j]);
                c[gcomp[p][j]] = 1;
            }
        }
        c[p] = 2;
        q.pop();
    }
    vector<bool> out(n);
    for (ll i : v)
    {
        out[i] = 1;
        for (ll j = 0; j < g[i].size(); j++)
        {
            out[g[i][j]] = 1;
        }
    }
    out[k-1] = 0;
    cout << count(out.begin(), out.end(), 1) << endl;
    for (ll i = 0; i < n; i++)
    {
        if (out[i] == 1) cout << i+1  << " ";
    }
}
 
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1824 KiB
2Accepted0/012ms4580 KiB
3Accepted2/23ms2304 KiB
4Accepted2/23ms2484 KiB
5Accepted2/23ms2808 KiB
6Accepted2/23ms2896 KiB
7Accepted2/23ms2868 KiB
8Accepted2/23ms3224 KiB
9Accepted2/23ms3320 KiB
10Accepted2/24ms3616 KiB
11Accepted2/24ms3876 KiB
12Accepted2/28ms4504 KiB
13Accepted2/27ms4716 KiB
14Accepted2/212ms5988 KiB
15Accepted3/318ms7880 KiB
16Accepted4/419ms7972 KiB
17Accepted4/427ms9012 KiB
18Accepted3/324ms8628 KiB
19Accepted3/320ms8192 KiB
20Accepted3/352ms13916 KiB
21Accepted3/359ms14952 KiB
22Accepted3/359ms15812 KiB