243612026-02-10 11:11:40szabel26Táblás játékcpp17Wrong answer 0/50197ms5428 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 << endl;
    for (auto &e : sol2)
        cout << e << " ";
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer1ms316 KiB
2Wrong answer197ms5428 KiB
subtask20/5
3Wrong answer1ms508 KiB
4Wrong answer1ms508 KiB
5Wrong answer1ms316 KiB
6Wrong answer1ms316 KiB
7Wrong answer1ms316 KiB
subtask30/5
8Wrong answer1ms508 KiB
9Wrong answer1ms316 KiB
10Wrong answer1ms316 KiB
11Wrong answer1ms316 KiB
12Wrong answer1ms316 KiB
subtask40/5
13Wrong answer1ms316 KiB
14Wrong answer1ms316 KiB
15Wrong answer2ms564 KiB
16Wrong answer2ms564 KiB
17Wrong answer12ms1612 KiB
subtask50/10
18Wrong answer1ms316 KiB
19Wrong answer1ms316 KiB
20Wrong answer1ms316 KiB
21Wrong answer1ms316 KiB
22Wrong answer1ms316 KiB
23Wrong answer1ms316 KiB
24Wrong answer1ms316 KiB
25Wrong answer1ms316 KiB
26Wrong answer2ms316 KiB
27Wrong answer34ms3932 KiB
subtask60/10
28Wrong answer1ms508 KiB
29Wrong answer2ms316 KiB
30Wrong answer1ms316 KiB
31Wrong answer1ms316 KiB
32Wrong answer1ms316 KiB
33Wrong answer1ms396 KiB
34Wrong answer1ms552 KiB
35Wrong answer1ms500 KiB
36Wrong answer2ms316 KiB
37Wrong answer32ms4064 KiB
subtask70/15
38Wrong answer3ms564 KiB
39Wrong answer9ms1084 KiB
40Wrong answer140ms4828 KiB
41Wrong answer144ms4404 KiB
42Wrong answer72ms2828 KiB
43Wrong answer39ms2396 KiB
44Wrong answer45ms2164 KiB
45Wrong answer6ms820 KiB
46Wrong answer37ms2356 KiB
47Wrong answer118ms3636 KiB
48Wrong answer16ms1076 KiB
49Wrong answer2ms316 KiB
50Wrong answer28ms1596 KiB
51Wrong answer64ms4408 KiB
52Wrong answer170ms4592 KiB