82592024-01-13 21:05:57bovizdbKerékpártúra (50 pont)cpp17Wrong answer 8/50500ms5760 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;

void solve()
{
    cin >> n >> m >> k;
    g.resize(n);
    for (ll i = 0; i < m; i++)
    {
        ll in1, in2;
        cin >> in1 >> in2;
        g[in1-1].push_back(in2-1);
    }
    vector<bool> out(n);
    for (ll i = 0; i < n; i++)
    {
        if (i == k-1) continue;
        if (out[i] == 1) continue;
        qll q;
        q.push(i);
        vll c(n, 0);
        bool b = 0;
        while(!q.empty())
        {
            ll p = q.front();
            for (ll j = 0; j < g[p].size(); j++)
            {
                if (g[p][j] == k-1)
                {
                    b = 1;
                    break;
                }
                if (c[g[p][j]] == 0)
                {
                    q.push(g[p][j]);
                    c[g[p][j]] = 1;
                }
            }
            if (b == 1)
            {
                break;
            }
            c[p] = 2;
            q.pop();
        }
        if (b == 1)
        {
            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
base8/50
1Wrong answer0/03ms1832 KiB
2Time limit exceeded0/0500ms2020 KiB
3Accepted2/23ms2276 KiB
4Accepted2/23ms2448 KiB
5Wrong answer0/23ms2664 KiB
6Wrong answer0/23ms2888 KiB
7Wrong answer0/23ms3104 KiB
8Wrong answer0/24ms3480 KiB
9Accepted2/26ms3448 KiB
10Accepted2/29ms3468 KiB
11Wrong answer0/239ms3784 KiB
12Wrong answer0/232ms4160 KiB
13Wrong answer0/261ms4104 KiB
14Wrong answer0/290ms4608 KiB
15Time limit exceeded0/3467ms3884 KiB
16Time limit exceeded0/4442ms4036 KiB
17Time limit exceeded0/4449ms4320 KiB
18Time limit exceeded0/3467ms4152 KiB
19Time limit exceeded0/3458ms3884 KiB
20Time limit exceeded0/3430ms5292 KiB
21Time limit exceeded0/3458ms5640 KiB
22Time limit exceeded0/3455ms5760 KiB