120952024-12-02 15:01:44madvirKerékpártúra (50 pont)cpp11Runtime error 0/50501ms32000 KiB
#include <iostream>
#include <set>
#include <iterator>

using namespace std;

int a[10001][10001]={0};
set<int> oda[10001], cel, tart, used;

int megy(int x, int k) {
    used.insert(x);
    //if(x==6) cout << 6666;
    for(set<int>::iterator ptr2=oda[x].begin(); ptr2!=oda[x].end(); ptr2++) {
        //cout << *ptr2 << " ";
        //if(x==6) cout << 6666 << "+" << *ptr2 <<" ";
        if(*ptr2==k || oda[*ptr2].find(k)!=oda[*ptr2].end()) {
            return 1;
        }
        else {
            if(used.find(*ptr2)==used.end()) {
                //if(x==6) cout << 6666 << "ujrahivas" << " ";
                megy(*ptr2,k);
            }
        }
    }
    //cout << endl;
    return 0;
}

int arra(int x, int k) {
    for(set<int>::iterator ptr=oda[x].begin(); ptr!=oda[x].end(); ptr++) {
        //cout << megy(*ptr,k) << " ";
        if(megy(*ptr,k)) {
            //cout << "*ptr=" << *ptr << endl;
            cel.insert(oda[*ptr].begin(),oda[*ptr].end());
            arra(*ptr,k);
        }
    }
    return 0;
}

int main()
{
    int n, m, k, x, y;
    cin >> n >> m >> k;
    for(int i=1; i<=m; i++) {
        cin >> x >> y;
        a[x][y]=1;
        oda[x].insert(y);
        if(x==k && y!=k) {
            //cout << "x=" << x << endl;
            tart.insert(y);
            cel.insert(y);
        }
    }
    for(set<int>::iterator ptr=tart.begin(); ptr!=tart.end(); ptr++) {
        //cout << *ptr << " : " << megy(*ptr,k) << " xxx ";
        used.empty();
        if(megy(*ptr,k)) {
            //cout << *ptr << endl;
            cel.insert(oda[*ptr].begin(), oda[*ptr].end());
            arra(*ptr,k);
        }
    }

    ///ird ki

    cel.erase(k);

    cout << cel.size() << endl;

    for(set<int>::iterator ptr=cel.begin(); ptr!=cel.end(); ptr++) {
        cout << *ptr << " ";
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Accepted0/02ms824 KiB
2Runtime error0/034ms32000 KiB
3Runtime error0/246ms32000 KiB
4Wrong answer0/21ms824 KiB
5Wrong answer0/21ms824 KiB
6Runtime error0/2389ms32000 KiB
7Runtime error0/281ms32000 KiB
8Runtime error0/2180ms32000 KiB
9Runtime error0/250ms32000 KiB
10Wrong answer0/24ms2796 KiB
11Wrong answer0/29ms6200 KiB
12Time limit exceeded0/2500ms8024 KiB
13Time limit exceeded0/2501ms29540 KiB
14Runtime error0/2360ms32000 KiB
15Runtime error0/337ms32000 KiB
16Runtime error0/437ms32000 KiB
17Runtime error0/437ms32000 KiB
18Runtime error0/337ms32000 KiB
19Runtime error0/335ms32000 KiB
20Runtime error0/386ms32000 KiB
21Runtime error0/339ms32000 KiB
22Runtime error0/334ms32000 KiB