135692025-01-08 10:05:47BencuKerékpártúra (50 pont)cpp17Runtime error 16/50500ms32000 KiB
#include <bits/stdc++.h>

using namespace std;
int n,m,k,a[10001][10001],c=1,megoldas[10001],C[10001],b[10001][10001];
void be() {
    ifstream f("be.in");
    cin>>n>>m>>k;
    //cout<<n<<m<<k;
    for (int i=1; i<=m; i++) {
        int x,y;
        cin>>x>>y;
        a[x][y]=1;
        b[x][y]=1;
    }
}
void jar (int x, int y) {
    if(x!=y) {
        for (int i=1; i<=n; i++) {
            if(a[x][i]==1 && a[y][i]==0) {
                a[y][i]=1;
                jar(i,y);
            }
        }
    }
}
void meg(int x) {
    megoldas[x]=1;
    for (int i=1; i<=n; i++) {
        if (b[x][i]==1 && megoldas[i]==0) {
            C[c]=i;
            c++;
            megoldas[i]=1;
            if(a[i][x]==1) meg(i);
        }
    }
}
int main()
{
    be();
    //cout<<"Hello World";
    /*for (int i=1; i<=n; i++) {
        for (int j=1; j<=n; j++) cout<<a[i][j]<<" ";
        cout<<endl;
    }
    cout<<endl;*/
    for (int i=1; i<=n; i++) {
        for (int j=1; j<=n; j++) if(a[i][j]==1) jar(j,i);
    }
    /*for (int i=1; i<=n; i++) {
        for (int j=1; j<=n; j++) cout<<a[i][j]<<" ";
        cout<<endl;
    }*/
    ///-----------------------------------------------------------Megoldas
    meg(k);
    cout<<c-1<<endl;
    for (int i=1; i<c; i++) cout<<C[i]<<" ";
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base16/50
1Accepted0/01ms316 KiB
2Runtime error0/035ms32000 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/21ms564 KiB
6Accepted2/22ms564 KiB
7Accepted2/23ms1076 KiB
8Accepted2/28ms1452 KiB
9Accepted2/237ms2100 KiB
10Accepted2/2105ms3468 KiB
11Time limit exceeded0/2500ms10804 KiB
12Time limit exceeded0/2483ms12844 KiB
13Time limit exceeded0/2483ms15160 KiB
14Time limit exceeded0/2490ms15816 KiB
15Runtime error0/332ms32000 KiB
16Runtime error0/432ms32000 KiB
17Runtime error0/427ms32000 KiB
18Runtime error0/334ms32000 KiB
19Runtime error0/327ms32000 KiB
20Runtime error0/359ms32000 KiB
21Runtime error0/337ms32000 KiB
22Runtime error0/328ms32000 KiB