95102024-02-22 13:09:22zeytonxTestnevelés óracpp17Wrong answer 2/501.1s127336 KiB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
//#define endl "\n"
#define pll pair<ll,ll>
#define vll vector<ll>
#define mll map<ll,ll>
#define fs first
#define sc second

const ll MOD = 1e9+7;

vector<vector<ll>> g;
vector<vector<ll>> ans;
ll ans_ind = -1;

void dfs(ll n, vector<ll> &used, vector<ll> bejart)
{
    if(ans_ind == 2 || ans_ind == 0)
        return;

    if(bejart.size() == g.size())
    {
        ans.push_back(bejart);
        ans_ind = ans.size();
        if(ans_ind == 2)
            return;
    }

    used[n] = 1;
    for(ll i : g[n])
        if(used[i])
            ans_ind = 0;
        else
        {
            bejart.push_back(i);
            dfs(i, used, bejart);
            bejart.pop_back();
        }
    used[n] = 0;
}

void solve()
{
	ll n, k;
    cin >> n >> k;
    g.assign(n, vector<ll>());
    set<ll> kezd;
    for(ll i = 0; i < n; i++)
        kezd.insert(i);
    for(ll i = 0; i < k; i++)
    {   
        ll a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        kezd.erase(b);
    }
    if(kezd.size() == 0)
    {
        cout << 0 << endl;
        return;
    }
    for(ll i : kezd)
    {
        vector<ll> used(n,0);
        dfs(i, used, {i});
        if(ans_ind == 0)
        {
            cout << 0 << endl;
            return;
        }
        if(ans_ind == 2)
        {
            cout << 2 << endl;
            for(auto i : ans)
            {
                for(ll j : i)
                    cout << j+1 << " ";
                cout << endl;
            }
        }
    }
    cout << ans_ind << endl;
    for(auto i : ans)
    {
        for(ll j : i)
            cout << j+1 << " ";
        cout << endl;
    }

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--)
        solve();
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base2/50
1Accepted0/03ms1828 KiB
2Wrong answer0/03ms2060 KiB
3Wrong answer0/0717ms21128 KiB
4Wrong answer0/23ms4740 KiB
5Wrong answer0/33ms4832 KiB
6Wrong answer0/32ms4836 KiB
7Wrong answer0/33ms5252 KiB
8Accepted1/13ms5252 KiB
9Wrong answer0/33ms5200 KiB
10Time limit exceeded0/31.098s5760 KiB
11Time limit exceeded0/31.08s5372 KiB
12Accepted1/14ms5972 KiB
13Time limit exceeded0/21.1s6000 KiB
14Wrong answer0/34ms6676 KiB
15Time limit exceeded0/11.1s18352 KiB
16Runtime error0/3177ms127336 KiB
17Time limit exceeded0/51.07s18448 KiB
18Time limit exceeded0/11.072s19696 KiB
19Time limit exceeded0/21.067s19088 KiB
20Runtime error0/3211ms127324 KiB
21Runtime error0/4212ms127300 KiB
22Runtime error0/4212ms127280 KiB