46482023-03-30 14:12:36EyusieTestnevelés óracpp17Wrong answer 8/501.1s50900 KiB
#include <bits/stdc++.h>
using namespace std;

list<int> a;
list<int> mx;
vector<vector<int>> magas(200001);
bool kor = false;
vector<bool> kors(200001, 0);
void dsearch(int v)
{
    if(kors[v]) kor = true;
    else
    {
        a.push_back(v);
        if(magas[v].size() == 0)
        {
            if(mx.size() < a.size())
            {
                mx = a;
            }
        }
        else
        {
                kors[v] = true;
        for(int i = 0; i< magas[v].size(); i++)
            {
                if(kor) break;
                dsearch(magas[v][i]);

            }
                kors[v] = false;

        }
        a.erase(prev(a.end()));
    }
}
int main()
{
    int n, k;
    cin >> n >> k;
    int m, v;
    set<int> e;
    set<int> x;
    for(int i = 0; i < n; i++)
    {
        x.insert(i);
        e.insert(i);
    }
    for(int i = 0; i < k; i++)
    {
        cin >> m >> v;
        magas[v-1].push_back(m-1);
        e.insert(v-1);
        e.erase(m-1);
        x.erase(v-1);
        x.erase(m-1);
    }
    for(set<int>::iterator itr = e.begin(); itr != e.end(); ++itr)
    {
    dsearch(*itr);
    }
    if(kor)
        cout << "0";
    else if(mx.size() == n)
    {
    cout << "1\n";
    for(list<int>::reverse_iterator itr = mx.rbegin(); itr != mx.rend(); ++itr)
    {
        cout << *itr+1 << " ";
    }
    }
    else
    {
        cout << "2\n";
        for(set<int>::reverse_iterator itr = x.rbegin(); itr != x.rend(); ++itr)
    {
        cout << *itr+1 << " ";
    }
    for(list<int>::reverse_iterator itr = mx.rbegin(); itr != mx.rend(); ++itr)
    {
        cout << *itr+1 << " ";
    }
     cout << "\n";

    for(list<int>::reverse_iterator itr = mx.rbegin(); itr != mx.rend(); ++itr)
    {
        cout << *itr+1 << " ";
    }
         for(set<int>::iterator itr = x.begin(); itr != x.end(); ++itr)
    {
        cout << *itr+1 << " ";
    }
    }
}
SubtaskSumTestVerdictTimeMemory
base8/50
1Accepted0/07ms11024 KiB
2Accepted0/07ms11272 KiB
3Wrong answer0/0578ms30124 KiB
4Wrong answer0/27ms11704 KiB
5Partially correct1/36ms11724 KiB
6Wrong answer0/36ms11728 KiB
7Wrong answer0/37ms11856 KiB
8Accepted1/16ms12068 KiB
9Wrong answer0/36ms12276 KiB
10Time limit exceeded0/31.057s7612 KiB
11Time limit exceeded0/31.078s7480 KiB
12Accepted1/18ms12704 KiB
13Time limit exceeded0/21.1s7756 KiB
14Wrong answer0/38ms13452 KiB
15Time limit exceeded0/11.1s12868 KiB
16Time limit exceeded0/31.062s20560 KiB
17Accepted5/5246ms50900 KiB
18Time limit exceeded0/11.072s27524 KiB
19Time limit exceeded0/21.062s13540 KiB
20Time limit exceeded0/31.074s39840 KiB
21Time limit exceeded0/41.077s41240 KiB
22Time limit exceeded0/41.069s41664 KiB