106902024-04-09 15:24:39VargusTestnevelés óracpp17Wrong answer 43/50236ms34372 KiB
#include <iostream>
#include <queue>
#include <algorithm>
#define ll long long

using namespace std;

struct adat
{
    bool lat = false;
    ll csop = 1, befok = 0;
    vector <ll> sz;
};
vector <adat> x;

deque <ll> v, poz;
bool kor = false;
void szelesseg(ll csp)
{
    v.push_front(csp);
    if(!x[csp].lat)
        poz.push_front(csp);
    while (!v.empty())
    {
        ll akt = v.front();
        v.pop_front();
        x[akt].lat = true;
        for (auto& e : x[akt].sz)
        {
            x[e].befok--;
            if (!x[e].befok)
            {
                v.push_front(e);
                x[e].csop = x[akt].csop + 1;
                poz.push_back(e);
            }
        }
    }
}

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].befok++;
    }

    for (ll i = 1; i <= n; ++i)
    {
        if (!x[i].befok)
        {
            szelesseg(i);
        }
    }
    if (poz.size() != n)
    {
        cout << "0";
        return 0;
    }
    else
    {
        for (ll i = 1; i < n; ++i)
        {
            if (x[poz[i - 1]].csop == x[poz[i]].csop)
            {
                cout << "2\n";
                for (auto& e : poz)
                    cout << e << " ";
                cout << endl;
                swap(poz[i], poz[i - 1]);
                for (auto& e : poz)
                    cout << e << " ";
                return 0;
            }
        }
        cout << "1\n";
        for (auto& e : poz)
            cout << e << " ";
    }

    return 0;
}
/*
5 9
3 1
3 5
3 4
4 2
3 2
1 4
1 2
1 5
5 4

5 3
2 1
3 2
1 5

4 4
1 2
2 3
3 4
4 2
*/
SubtaskSumTestVerdictTimeMemory
base43/50
1Accepted0/03ms1712 KiB
2Accepted0/03ms2020 KiB
3Wrong answer0/0194ms19420 KiB
4Accepted2/23ms2296 KiB
5Accepted3/33ms2376 KiB
6Accepted3/33ms2380 KiB
7Accepted3/33ms2600 KiB
8Accepted1/13ms2592 KiB
9Accepted3/33ms2724 KiB
10Accepted3/34ms3140 KiB
11Accepted3/34ms3116 KiB
12Wrong answer0/14ms3116 KiB
13Accepted2/24ms3120 KiB
14Wrong answer0/33ms3096 KiB
15Accepted1/1163ms14620 KiB
16Wrong answer0/3150ms24740 KiB
17Accepted5/567ms25484 KiB
18Accepted1/1236ms34372 KiB
19Accepted2/2167ms15640 KiB
20Accepted3/3202ms29648 KiB
21Accepted4/4187ms29648 KiB
22Accepted4/4207ms29576 KiB