179702025-09-24 18:01:49algoproTestnevelés óracpp17Wrong answer 7/50209ms12072 KiB
// UUID: addd31f9-85d3-4414-97f1-98ea4f9714ba
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <queue>
#include <vector>
using namespace std;

//A maximális int az 2^31-1 ami nagyobb mint 10^9 de kisseb mint 10^10

int main() {
int n, t;
    cin >> n >> t;

    vector<vector<int>> fa(n);
    vector<int> indeg(n, 0);

    for (int i = 0; i < t; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        fa[a].push_back(b);
        indeg[b]++;
    }

    queue<int> q;
    for (int i = 0; i < n; i++) {
        if (indeg[i] == 0) q.push(i);
    }

    vector<int> lista;
    int count = 0;

    while (!q.empty()) {
        if (q.size() > 1) count++; 

        int u = q.front();
        q.pop();
        lista.push_back(u);

        for (int v : fa[u]) {
            indeg[v]--;
            if (indeg[v] == 0) q.push(v);
        }
    }

    if ((int)lista.size() != n) {
        cout << 0;
        return 0;
    }

    cout << count+1 << "\n";
    for (int x : lista) cout << x + 1 << " ";
    cout << "\n";
}
SubtaskSumTestVerdictTimeMemory
base7/50
1Accepted0/01ms316 KiB
2Wrong answer0/01ms316 KiB
3Wrong answer0/0186ms6588 KiB
4Wrong answer0/21ms508 KiB
5Wrong answer0/31ms316 KiB
6Wrong answer0/31ms352 KiB
7Wrong answer0/31ms316 KiB
8Accepted1/11ms316 KiB
9Wrong answer0/31ms316 KiB
10Wrong answer0/32ms316 KiB
11Wrong answer0/33ms448 KiB
12Accepted1/13ms436 KiB
13Accepted2/22ms316 KiB
14Wrong answer0/31ms316 KiB
15Accepted1/1158ms4476 KiB
16Wrong answer0/3123ms8960 KiB
17Wrong answer0/534ms8892 KiB
18Wrong answer0/1209ms12072 KiB
19Accepted2/2158ms4528 KiB
20Wrong answer0/3167ms10668 KiB
21Wrong answer0/4164ms10668 KiB
22Wrong answer0/4167ms10668 KiB