105502024-04-05 09:53:58VargusTestnevelés óracpp17Wrong answer 25/50256ms67332 KiB
#include <iostream>
#include <queue>
#include <algorithm>
#define ll long long

using namespace std;

struct adat
{
    bool lat, kilep;
    ll ido = 0;
    vector <ll> sz, ut;
};
vector <adat> x;

bool kor = false;
deque <ll> q;
void melyseg(ll csp)
{
    x[csp].lat = true;
    for (auto& e : x[csp].sz)
    {
        x[e].ido += x[csp].ut.size() + 1;
        if (x[e].lat && !x[e].kilep)
        {
            kor = true;
        }
        if (!x[e].lat)
        {
            melyseg(e);
        }
    }
    q.push_front(csp);
    x[csp].kilep = true;
}

int main()
{
    ll n, k;
    cin >> n >> k;
    x.resize(n + 1);
    for (ll i = 1; i <= k; ++i)
    {
        ll cs1, cs2;
        cin >> cs1 >> cs2;
        x[cs1].sz.push_back(cs2);
        x[cs2].ut.push_back(cs1);
    }
    ll db = 0;
    for (ll i = 1; i <= n; ++i)
    {
        if (!x[i].ut.size())
        {
            ++db;
            melyseg(i);
            if (kor)
            {
                cout << "0";
                return 0;
            }
        }
    }   
    if (db == 1)
    {
        cout << db << "\n";
        for (ll j = 0; j <= q.size()-1; ++j)
            cout << q[j] << " ";
        return 0;
    }
    
    else if (db == 0)
    {
        cout << "0\n";
        return 0;
    }
    else if (db >= 2)
        cout << "2\n";
    {
        for (ll j = 0; j <= q.size() - 1; ++j)
            cout << q[j] << " ";
        for (ll i = 1; i <= q.size() - 1; ++i)
        {
            if (x[q[i]].ido == x[q[i - 1]].ido)
            {
                swap(q[i], q[i - 1]);
                cout << "\n";
                for (ll j = 0; j <= q.size() - 1; ++j)
                    cout << q[j] << " ";
                break;
            }
        }
    }

}
/*
5 3
2 1
3 2
1 5

5 9
3 1
3 5
3 4
4 2
3 2
1 4
1 2
1 5
5 4

*/
SubtaskSumTestVerdictTimeMemory
base25/50
1Accepted0/03ms1808 KiB
2Accepted0/03ms2064 KiB
3Accepted0/0222ms29172 KiB
4Wrong answer0/23ms2096 KiB
5Accepted3/33ms2352 KiB
6Wrong answer0/33ms2444 KiB
7Accepted3/33ms2656 KiB
8Accepted1/13ms2880 KiB
9Wrong answer0/32ms2956 KiB
10Wrong answer0/34ms3352 KiB
11Wrong answer0/34ms3716 KiB
12Accepted1/14ms3792 KiB
13Accepted2/24ms3892 KiB
14Accepted3/33ms3852 KiB
15Accepted1/1182ms22876 KiB
16Accepted3/3174ms35220 KiB
17Accepted5/564ms32060 KiB
18Accepted1/1256ms47708 KiB
19Accepted2/2181ms24192 KiB
20Wrong answer0/3216ms67332 KiB
21Wrong answer0/4217ms67180 KiB
22Wrong answer0/4222ms67184 KiB