180502025-09-25 18:36:08algoproTestnevelés óracpp17Wrong answer 2/5081ms10908 KiB
// UUID: e05fa0df-38b9-4b5c-b3ed-29bc0452878b
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k; cin >> n >> k;
    vector<vector<int>> g(n + 1);
    vector<int> beelek(n + 1, 0);
    vector<vector<int>> solutions(2);
    for (int i = 0; i < k; i++) {
        int a, b; cin >> a >> b;
        g[b].push_back(a);
        beelek[b]++;
    }
    beelek[0] = -1;
    while (!all_of(begin(beelek), end(beelek), [](int i) { return i < 0; })) {
        vector<int> forrasok;
        for (int i = 1; i <= n; i++) {
            if (beelek[i] == 0) {
                forrasok.push_back(i);
            }
        }
        if (forrasok.size() == 0) {
            cout << 0; return 0;
        }
        else {
            for (int i = 0; i < forrasok.size(); i++) {
                solutions[0].push_back(forrasok[i]);
                solutions[1].push_back(forrasok[forrasok.size() - 1 - i]);
            }
        }
        for (int j : forrasok) {
            beelek[j] = -1;
            for (int i : g[j]) {
                beelek[i]--;
            }
        }
        
    }
    int o = 1;
    for (int i = 0; i < n; i++) {
        if (solutions[0][i] != solutions[1][i]) {
            o = 2; break;
        }
    }
    cout << o << endl;
    for (int i : solutions[0]) {
        cout << i << " ";
    }
    cout << endl;
    if (o == 2) {
        for (int i : solutions[1]) {
            cout << i << " ";
        }
    }
}
// #include <bits/stdc++.h>
// #include <vector>
// #include <numeric>

// using namespace std;

// int main() {
//     ios::sync_with_stdio(false);
//     cin.tie(0);
//     int n, k; cin >> n >> k;
//     vector<vector<int>> g(n + 1);
//     vector<int> beelek(n + 1, 0);
//     vector<vector<int>> solutions(2);
//     for (int i = 0; i < k; i++) {
//         int a, b; cin >> a >> b;
//         g[a].push_back(b);
//         beelek[b]++;
//     }
//     beelek[0] = -1;
//     // sor letrehozas
//     queue<int> forrasok;
//     vector<int> sorrend;
//     // sorba bepakoljuk az osszes forrast
//     for (int i = 1; i <= n; i++) {
//         if (beelek[i] == 0) {
//             forrasok.push(i);
//         }
//     }
//     while (forrasok.size() != 0) {
//         // kiszedunk 1 forrast a sorbol
//         // toroljuk az ő éleit és a sorrend végére tesszük

//         int x = forrasok.front();
//         forrasok.pop();
//         sorrend.push_back(x);

//         for (int i : g[x]){
//             --beelek[i];
//             if(beelek[i] == 0) forrasok.push(i);
//         }
//     }

//     if (sorrend.size()<n){
//         cout<<0; return 0;
//     }
//     vector<int> sorrend2;
//     for(int i = 0 ; i < n - 1; i++){
//         if (find(g[sorrend[i]].begin(), g[sorrend[i]].end(), sorrend[i+1]) != g[sorrend[i]].end()){
//             // sorrend2 = 
//         }
//     }
//     // for(int i = 0; i < n; i++){
//     //     cout<<sorrend[i];
//     // }
// }


// /*


// beolvasasás
// befokok számolása

// sor létrehozása
// források a sorba

// queue <int> q;
// vector <int> ans;

// while (q.size()>0){
    
//     int x = q.front();
//     q.pop();

//     for (int y : g[x]) {
//         y befokát csökkentem
//         ha 0-ra csökkent, akkor beteszem a sorba
//     }

// }

// ans mérete alapján eldöntöm

// ----------------------------------------

// Létezik-e több?


// */
SubtaskSumTestVerdictTimeMemory
base2/50
1Wrong answer0/01ms500 KiB
2Wrong answer0/01ms316 KiB
3Wrong answer0/081ms5940 KiB
4Wrong answer0/21ms316 KiB
5Wrong answer0/31ms316 KiB
6Wrong answer0/31ms316 KiB
7Wrong answer0/31ms352 KiB
8Accepted1/11ms316 KiB
9Wrong answer0/31ms316 KiB
10Wrong answer0/32ms508 KiB
11Wrong answer0/32ms316 KiB
12Accepted1/12ms316 KiB
13Wrong answer0/22ms316 KiB
14Wrong answer0/31ms316 KiB
15Wrong answer0/164ms3760 KiB
16Wrong answer0/354ms6976 KiB
17Wrong answer0/59ms9040 KiB
18Wrong answer0/175ms10908 KiB
19Wrong answer0/264ms3892 KiB
20Wrong answer0/368ms9088 KiB
21Wrong answer0/471ms9232 KiB
22Wrong answer0/457ms9200 KiB