10511 | 2024-04-04 09:59:17 | RRoli | Kritikus munkák | cpp17 | Time limit exceeded 0/100 | 400ms | 12560 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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1912 KiB | ||||
2 | Time limit exceeded | 400ms | 7492 KiB | ||||
subtask2 | 0/25 | ||||||
3 | Accepted | 3ms | 2440 KiB | ||||
4 | Time limit exceeded | 400ms | 2660 KiB | ||||
5 | Time limit exceeded | 372ms | 3080 KiB | ||||
6 | Time limit exceeded | 349ms | 2952 KiB | ||||
7 | Accepted | 14ms | 3408 KiB | ||||
subtask3 | 0/25 | ||||||
8 | Time limit exceeded | 400ms | 4028 KiB | ||||
9 | Time limit exceeded | 356ms | 2932 KiB | ||||
10 | Time limit exceeded | 381ms | 3004 KiB | ||||
11 | Time limit exceeded | 374ms | 3388 KiB | ||||
12 | Time limit exceeded | 368ms | 3364 KiB | ||||
subtask4 | 0/25 | ||||||
13 | Accepted | 41ms | 11564 KiB | ||||
14 | Time limit exceeded | 400ms | 7316 KiB | ||||
15 | Time limit exceeded | 400ms | 7244 KiB | ||||
16 | Time limit exceeded | 368ms | 7432 KiB | ||||
17 | Time limit exceeded | 354ms | 7316 KiB | ||||
subtask5 | 0/25 | ||||||
18 | Time limit exceeded | 377ms | 12560 KiB | ||||
19 | Time limit exceeded | 374ms | 12420 KiB | ||||
20 | Time limit exceeded | 377ms | 12428 KiB | ||||
21 | Time limit exceeded | 374ms | 12528 KiB | ||||
22 | Time limit exceeded | 374ms | 12404 KiB |