243622026-02-10 11:23:14szabel26Táblás játékcpp17Wrong answer 0/50194ms5428 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(int i)
{
    for (int j = 1; j <= n; ++j)
    {
        if (x[j].szint == i && x[j].lat == 0 && sol1.size() < i)
        {
            sol1.push_back(j);
            x[j].lat = 1;
        }
        if (x[j].szint == i && x[j].lat == 0 && sol2.size() < i)
        {
            sol2.push_back(j);
            x[j].lat = 1;
        }
    }

    if (sol1.size() < i || sol2.size() < i)
        for (int j = 1; j <= n; ++j)
        {
            if (x[j].szint == i)
            {
                if (sol1.size() < i)
                    sol1.push_back(j);
                if (sol2.size() < i)
                    sol2.push_back(j);
                x[j].lat = 1;
            }
        }
}

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];
    }

    for (int i = 1; i <= szint_max; ++i) // feltetelezve, hogy mindig az utolso szinten levo csp egy celpont
    {
        keres(i);
        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 answer194ms5428 KiB
subtask20/5
3Accepted2ms316 KiB
4Accepted1ms316 KiB
5Accepted1ms508 KiB
6Wrong answer2ms316 KiB
7Wrong answer1ms316 KiB
subtask30/5
8Wrong answer1ms316 KiB
9Wrong answer1ms316 KiB
10Wrong answer1ms500 KiB
11Wrong answer1ms316 KiB
12Wrong answer1ms316 KiB
subtask40/5
13Wrong answer1ms316 KiB
14Wrong answer1ms316 KiB
15Wrong answer2ms564 KiB
16Wrong answer2ms564 KiB
17Wrong answer10ms1540 KiB
subtask50/10
18Accepted1ms316 KiB
19Wrong answer2ms316 KiB
20Wrong answer1ms316 KiB
21Wrong answer1ms500 KiB
22Wrong answer1ms316 KiB
23Wrong answer1ms404 KiB
24Wrong answer1ms316 KiB
25Wrong answer1ms316 KiB
26Wrong answer2ms316 KiB
27Wrong answer32ms4080 KiB
subtask60/10
28Accepted1ms508 KiB
29Wrong answer1ms316 KiB
30Accepted1ms316 KiB
31Wrong answer1ms512 KiB
32Wrong answer1ms316 KiB
33Wrong answer1ms508 KiB
34Wrong answer1ms316 KiB
35Wrong answer1ms316 KiB
36Wrong answer2ms316 KiB
37Wrong answer34ms3864 KiB
subtask70/15
38Wrong answer3ms564 KiB
39Wrong answer8ms1076 KiB
40Wrong answer138ms4840 KiB
41Wrong answer150ms4400 KiB
42Wrong answer68ms2832 KiB
43Wrong answer39ms2376 KiB
44Wrong answer50ms1824 KiB
45Wrong answer6ms820 KiB
46Wrong answer37ms2100 KiB
47Wrong answer119ms3636 KiB
48Wrong answer16ms1160 KiB
49Accepted2ms316 KiB
50Wrong answer29ms1792 KiB
51Wrong answer63ms4420 KiB
52Wrong answer168ms4660 KiB