105112024-04-04 09:59:17RRoliKritikus munkákcpp17Time limit exceeded 0/100400ms12560 KiB
#include <bits/stdc++.h>
using namespace std;

struct lista{
    int sz;
    lista *kov;
} *elso[100001]={NULL}, *utolso[100001];
int n, m, be[100001], bejart[100001], szam;

void bejar(int k) {
    int eredeti = szam;
    lista *p = elso[k];
    if(p == 0) szam++;
    while(p != 0) {
        bejar(p->sz);
        p = p->kov;
    }
    bejart[k] += (szam - eredeti);
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin>> n >> m;

    lista *p;
    for(int i = 1; i <= m; i++) {
        int x, y;
        cin>> x >> y;
        be[y]++;
        p = new lista;
        if(elso[x] == NULL) elso[x] = p;
        else utolso[x]->kov = p;
        p->kov = NULL;
        p->sz = y;
        utolso[x] = p;
    }

    for(int i = 1; i <= n; i++)
        if(be[i] == 0)
            bejar(i);

    int t = 0;
    for(int i = 1; i <= n; i++)
        if(bejart[i] == szam)
            t++;

    cout << t << endl;
    for(int i = 1; i <= n; i++)
        if(bejart[i] == szam)
            cout << i << ' ';


    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1912 KiB
2Time limit exceeded400ms7492 KiB
subtask20/25
3Accepted3ms2440 KiB
4Time limit exceeded400ms2660 KiB
5Time limit exceeded372ms3080 KiB
6Time limit exceeded349ms2952 KiB
7Accepted14ms3408 KiB
subtask30/25
8Time limit exceeded400ms4028 KiB
9Time limit exceeded356ms2932 KiB
10Time limit exceeded381ms3004 KiB
11Time limit exceeded374ms3388 KiB
12Time limit exceeded368ms3364 KiB
subtask40/25
13Accepted41ms11564 KiB
14Time limit exceeded400ms7316 KiB
15Time limit exceeded400ms7244 KiB
16Time limit exceeded368ms7432 KiB
17Time limit exceeded354ms7316 KiB
subtask50/25
18Time limit exceeded377ms12560 KiB
19Time limit exceeded374ms12420 KiB
20Time limit exceeded377ms12428 KiB
21Time limit exceeded374ms12528 KiB
22Time limit exceeded374ms12404 KiB