116132024-10-31 19:03:25csdavidKerékpártúra (50 pont)cpp17Wrong answer 20/50136ms5556 KiB
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

struct david{
    vector<int> v;
};

int main()
{
    int n, m, k, x, y;
    cin >> n >> m >> k;
    queue<int> q;
    david a[n+1], b[n+1];
    int bejart[n+1], jo[n+1];
    for(auto& it: bejart){
        it=0;
    }
    for(auto& it:jo){
        it=0;
    }
    bejart[k]=1;
    for(int i=0; i<m; i++){
        cin >> x >> y;
        a[x].v.push_back(y);
        b[y].v.push_back(x);
    }
    q.push(k);
    /*cout << "\n\n";
    for(int i=1; i<=n; i++){
        for(int j=0; j<b[i].size(); j++){
            cout << i << ' ' << b[i][j] << '\n';
        }
    }*/
    while(!q.empty()){
        /*cout << 'x';
        cout << b[q.front()].v.size();*/
        for(int i=0; i<b[q.front()].v.size(); i++){

            if(bejart[b[q.front()].v[i]]==0){
                q.push(b[q.front()].v[i]);
                x=b[q.front()].v[i];
                bejart[b[q.front()].v[i]]=1;
                jo[b[q.front()].v[i]]=1;
                for(int j=0; j<a[x].v.size(); j++){
                    jo[a[x].v[j]]=1;
                }
            }
        }
        q.pop();
    }
    jo[k]=0;
    int megoldas=0;
    for(int i=1; i<=n; i++){
        if(jo[i]==1){
            megoldas++;
        }
    }

    cout << megoldas << '\n';
    for(int i=1; i<=n; i++){
        if(jo[i]==1){
            cout << i << ' ';
        }
    }




    return 0;
}
SubtaskSumTestVerdictTimeMemory
base20/50
1Accepted0/01ms500 KiB
2Wrong answer0/019ms1848 KiB
3Accepted2/21ms320 KiB
4Accepted2/21ms320 KiB
5Accepted2/21ms508 KiB
6Wrong answer0/21ms568 KiB
7Wrong answer0/21ms320 KiB
8Wrong answer0/23ms320 KiB
9Accepted2/23ms472 KiB
10Accepted2/24ms320 KiB
11Wrong answer0/24ms568 KiB
12Wrong answer0/212ms868 KiB
13Wrong answer0/210ms788 KiB
14Wrong answer0/220ms1136 KiB
15Wrong answer0/335ms2212 KiB
16Wrong answer0/437ms2216 KiB
17Accepted4/454ms2748 KiB
18Accepted3/346ms2552 KiB
19Accepted3/341ms2360 KiB
20Wrong answer0/3119ms4904 KiB
21Wrong answer0/3135ms5372 KiB
22Wrong answer0/3136ms5556 KiB