44382023-03-28 08:50:40AGergoTestnevelés óracpp17Wrong answer 1/501.1s126720 KiB
#include <bits/stdc++.h>

using namespace std;

int diakszam,emlekszam;
vector<vector<int>> graf;
vector<int> temp;

vector<int> v1;
vector<int> v2;

void rek(int kezd, int szint, vector<int> eljut)
{
    if(graf[kezd].size() == 0 && szint == diakszam)
    {
        /*cout << "1\n" << kezd << " ";
        for(int i = szint-2; i > -1; i--)
        {
            cout << eljut[i] << " ";
        }*/
        if(v1.size() == 0)
        {
            v1 = eljut;
            v1.push_back(kezd);
        }
        else if(v2.size() == 0)
        {
            v2 = eljut;
            v2.push_back(kezd);
            if(v1 == v2){v2.clear();}
        }
    }
    else if(szint < diakszam)
    {
        for(int x : graf[kezd])
        {
            temp = eljut;
            temp.push_back(kezd);
            rek(x,szint+1,temp);
        }
    }
}


int main()
{
    ios::sync_with_stdio(0); cin.tie(0);


    cin >> diakszam >> emlekszam;
    graf.resize(diakszam+1);

    vector<bool> van(diakszam+1);

    int a,b;

    for(int i = 0;i < emlekszam; i++)
    {
        cin >> a >> b;
        graf[b].push_back(a);
        van[a] = true;
    }

    for(int i = 1; i < diakszam+1; i++)
    {
        if(!van[i])
        {
            rek (i,1,{});
            break;
        }
    }

    if(v1.size() == 0)
    {
        cout << 0;
    }
    else if(v2.size() == 0)
    {
        cout << "1\n";
        for(int i = diakszam-1; i > -1; i--)
        {
            cout << v1[i] << " ";
        }
    }
    else
    {
        cout << 2;
        for(int i = diakszam-1; i > -1; i--)
        {
            cout << v1[i] << " ";
        }
        cout << '\n';
        for(int i = diakszam-1; i > -1; i--)
        {
            cout << v2[i] << " ";
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base1/50
1Accepted0/03ms1824 KiB
2Wrong answer0/03ms2020 KiB
3Wrong answer0/064ms11492 KiB
4Wrong answer0/23ms2328 KiB
5Wrong answer0/33ms2676 KiB
6Wrong answer0/33ms2632 KiB
7Wrong answer0/33ms2768 KiB
8Wrong answer0/13ms2976 KiB
9Wrong answer0/33ms3116 KiB
10Time limit exceeded0/31.049s3564 KiB
11Time limit exceeded0/31.052s2876 KiB
12Accepted1/13ms3800 KiB
13Time limit exceeded0/21.1s4292 KiB
14Wrong answer0/33ms4256 KiB
15Time limit exceeded0/11.1s8968 KiB
16Runtime error0/3228ms126720 KiB
17Wrong answer0/57ms13452 KiB
18Wrong answer0/170ms20288 KiB
19Time limit exceeded0/21.07s10656 KiB
20Runtime error0/390ms126520 KiB
21Runtime error0/4101ms126296 KiB
22Runtime error0/4101ms126060 KiB