180532025-09-25 18:39:20algoproTestnevelés óracpp17Runtime error 27/5064ms64000 KiB
// UUID: 6848f629-da63-4f61-92f5-6c6f4db42c71
#include <bits/stdc++.h>
#include <queue>
using namespace std;

#define int long long
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;cin >> n >> m;
    vector<vector<int>> g(n+1, vector<int>(n+1));
    vector<int> c(n+1, 0);
    for(int i = 0; i < m; i++)
    {
        int a,b;cin >> a >> b;
        c[b]++;
        g[a].push_back(b);
    }
    queue<int> q;
    vector<int> ans;
    for(int i = 1; i <= n; i++) if(c[i] == 0) q.push(i); 
    while(!q.empty())
    {
        int v = q.front();
        ans.push_back(v);
        q.pop();
       
        for(int e: g[v])
        {
            c[e]--;
            if(c[e] == 0) q.push(e);
        }
    }
    if(ans.size() < n)
    {
        cout << "0";
        return 0;
    }
    vector<int>ans2 = ans;
    for(int i = 0; i < n-1; i++)
    {
        int a = ans[i];int b = ans[i+1];
        bool connected = false;
        for(int e: g[a])
        {
            if(e == b) connected = true;
        }
        if(!connected)
        {
            swap(ans2[i], ans2[i+1]);
            cout << "2\n";
            for(int v: ans) cout << v << " ";
            cout << "\n";
            for(int v: ans2) cout << v << " ";
            return 0;
        }         
    }
    cout << "1\n";
    for(int a: ans) cout << a << " ";
    
 
    
    

}

/*


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
base27/50
1Accepted0/01ms316 KiB
2Accepted0/01ms316 KiB
3Runtime error0/061ms64000 KiB
4Accepted2/21ms316 KiB
5Accepted3/31ms316 KiB
6Accepted3/31ms316 KiB
7Accepted3/31ms316 KiB
8Accepted1/11ms316 KiB
9Accepted3/31ms316 KiB
10Accepted3/312ms8460 KiB
11Accepted3/314ms14092 KiB
12Accepted1/116ms14836 KiB
13Accepted2/220ms14792 KiB
14Accepted3/316ms14900 KiB
15Runtime error0/152ms64000 KiB
16Runtime error0/350ms64000 KiB
17Runtime error0/564ms64000 KiB
18Runtime error0/163ms64000 KiB
19Runtime error0/261ms64000 KiB
20Runtime error0/361ms64000 KiB
21Runtime error0/450ms64000 KiB
22Runtime error0/461ms64000 KiB