243632026-02-10 11:43:55szabel26Táblás játékcpp17Wrong answer 20/5064ms5428 KiB
#include <iostream>
#include <vector>
#include <deque>
using namespace std;

struct adat
{
    vector<int> be;
    vector<int> ki;
    int be_db;
    int ki_db;
    int szint;
    int lat = 0;
};

deque<int> kov;
vector<adat> x;
vector<int> szint_st, sol1, sol2;

int n, m, a, b, szint_max, db;

void szelessegi(int akt)
{
    szint_max = max(szint_max, x[akt].szint);
    for (auto &e : x[akt].ki)
    {
        if (x[e].szint == 0 || x[e].szint < x[akt].szint + 1)
        {
            x[e].szint = x[akt].szint + 1;
            kov.push_back(e);
        }
    }
}

void keres()
{
    for (int i = 1; i <= n; ++i)
    {
        if (x[i].szint == 1)
        {
            a = i;
            break;
        }
    }
    for (int i = a + 1; i <= n; ++i)
    {
        if (x[i].szint == 1)
        {
            b = i;
            break;
        }
    }

    if (b == 0)
        b = a;
}

void bejar(int akt1, int akt2)
{
    pair<int, int> kov = {-1, -1};
    sol1.push_back(akt1);
    sol2.push_back(akt2);
    for (auto &e : x[akt1].ki)
    {
        if (szint_st[x[e].szint] >= 2)
        {
            if (x[e].lat == 0)
            {
                kov.first = e;
                x[e].lat = 1;
                break;
            }
        }
        else
        {
            kov.first = e;
            x[e].lat = 1;
            break;
        }
    }

    for (auto &e : x[akt2].ki)
    {
        if (szint_st[x[e].szint] >= 2)
        {
            if (x[e].lat == 0)
            {
                kov.second = e;
                x[e].lat = 1;
                break;
            }
        }
        else
        {
            kov.second = e;
            x[e].lat = 1;
            break;
        }
    }

    if(kov.first != -1 && kov.second != -1) bejar(kov.first, kov.second);
}

int main()
{
    cin >> n >> m;
    x.resize(n + 1);
    for (int i = 1; i <= m; ++i)
    {
        cin >> a >> b;

        x[a].ki.push_back(b);
        x[a].ki_db = x[a].ki.size();

        x[b].be.push_back(a);
        x[b].be_db = x[b].be.size();
    }

    for (int i = 1; i <= n; ++i)
    {
        if (x[i].be_db == 0)
        {
            x[i].szint = 1;
            kov.push_back(i);
        }
    }

    while (!kov.empty())
    {
        szelessegi(kov[0]);
        kov.pop_front();
    }

    szint_st.resize(szint_max + 1);
    for (int i = 1; i <= n; ++i)
    {
        ++szint_st[x[i].szint];
    }

    a = 0;
    b = 0;
    keres();
    bejar(a, b);
    for (int i = 1; i <= szint_max; ++i) // feltetelezve, hogy mindig az utolso szinten levo csp egy celpont
    {
        if (szint_st[i] >= 2)
        {
            db += 2;
        }
        else
            db += szint_st[i];
    }

    cout << db << endl;

    for (auto &e : sol1)
        cout << e << " ";
    cout << 0 << endl;

    for (auto &e : sol2)
        cout << e << " ";
    cout << 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms316 KiB
2Wrong answer64ms5428 KiB
subtask25/5
3Accepted1ms512 KiB
4Accepted1ms508 KiB
5Accepted1ms316 KiB
6Accepted1ms508 KiB
7Accepted1ms316 KiB
subtask30/5
8Wrong answer1ms500 KiB
9Wrong answer1ms316 KiB
10Accepted1ms316 KiB
11Accepted1ms316 KiB
12Accepted1ms316 KiB
subtask45/5
13Accepted1ms324 KiB
14Accepted1ms316 KiB
15Accepted2ms564 KiB
16Accepted2ms564 KiB
17Accepted12ms1604 KiB
subtask50/10
18Accepted1ms508 KiB
19Wrong answer1ms508 KiB
20Wrong answer1ms316 KiB
21Wrong answer1ms508 KiB
22Accepted1ms316 KiB
23Wrong answer1ms316 KiB
24Accepted1ms316 KiB
25Accepted1ms316 KiB
26Wrong answer2ms316 KiB
27Wrong answer30ms3908 KiB
subtask610/10
28Accepted2ms336 KiB
29Accepted2ms316 KiB
30Accepted2ms316 KiB
31Accepted2ms508 KiB
32Accepted1ms316 KiB
33Accepted1ms508 KiB
34Accepted1ms316 KiB
35Accepted1ms508 KiB
36Accepted2ms316 KiB
37Accepted30ms3876 KiB
subtask70/15
38Accepted3ms568 KiB
39Wrong answer8ms1076 KiB
40Wrong answer59ms4660 KiB
41Wrong answer52ms4396 KiB
42Wrong answer28ms2628 KiB
43Wrong answer25ms2360 KiB
44Wrong answer17ms1844 KiB
45Wrong answer6ms856 KiB
46Wrong answer21ms2068 KiB
47Wrong answer41ms3544 KiB
48Wrong answer8ms1076 KiB
49Accepted2ms508 KiB
50Wrong answer16ms1700 KiB
51Accepted50ms4300 KiB
52Wrong answer54ms4588 KiB