47032023-03-31 09:43:35EyusieTestnevelés óracpp17Wrong answer 8/501.1s51516 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 if(kor) return;
    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()
{   iostream::sync_with_stdio(0);
    cin.tie();
    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/07ms11216 KiB
3Wrong answer0/0477ms29964 KiB
4Wrong answer0/27ms11688 KiB
5Partially correct1/36ms11856 KiB
6Wrong answer0/37ms12080 KiB
7Wrong answer0/37ms12292 KiB
8Accepted1/16ms12508 KiB
9Wrong answer0/36ms12728 KiB
10Time limit exceeded0/31.1s7868 KiB
11Time limit exceeded0/31.057s7900 KiB
12Accepted1/18ms13528 KiB
13Time limit exceeded0/21.034s8296 KiB
14Wrong answer0/39ms13876 KiB
15Time limit exceeded0/11.1s13156 KiB
16Time limit exceeded0/31.018s21208 KiB
17Accepted5/5238ms51516 KiB
18Time limit exceeded0/11.057s27768 KiB
19Time limit exceeded0/21.046s13716 KiB
20Time limit exceeded0/31.075s38220 KiB
21Time limit exceeded0/41.041s41552 KiB
22Time limit exceeded0/41.052s41524 KiB