68512023-12-19 11:44:06zsebiTestnevelés óracpp17Wrong answer 3/50365ms73564 KiB
// testneveles.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <queue>

#define ll long long
using namespace std;
ll n, m;
struct adat
{
    bool lat1 = false,lat=false;
    ll latk = 0,csop;
    vector<ll>sz,sz2;
};
deque<ll>ans, ans2;
vector<adat>x;
bool ok1 = false;
void melyk(int csp)
{
    if (ok1 == true)return;
    x[csp].latk = 1;
    for (auto& e:x[csp].sz)
    {
        if (!x[e].latk)melyk(e);
        else if (x[e].latk != 2)
        {
           
            ok1 = true;
            break;
        }
    }
    x[csp].latk = 2;
}
void mely(int csp,int csop)
{
    x[csp].lat = true;
    x[csp].csop = csop;
    for (auto& e : x[csp].sz2)
        if (!x[e].lat)mely(e,csop);
    //ans.push_front(csp);
}
void mely2(int csp)
{
    x[csp].lat1 = true;
    for (auto& e : x[csp].sz)
        if (!x[e].lat1)mely2(e);
    ans.push_front(csp);
}
void mely3(int csp)
{
    x[csp].lat1 = true;
    for (auto& e : x[csp].sz)
        if (!x[e].lat1)mely2(e);
    ans2.push_front(csp);
}
int main()
{
    cin >> n >> m;
    x.resize(n + 1);
    for (int i = 1; i <= m; ++i)
    {
        ll a, b;
        cin >> a >> b;
        x[a].sz.push_back(b);
        x[a].sz2.push_back(b);
        x[b].sz2.push_back(a);
    }
    bool ok = false, ok2 = false;
    for (int i = 1; i <= n; ++i)
    {
        if (!x[i].latk)melyk(i);
    }
    if (ok1)
    {
        cout << "0";
        return 0;
    }
    int csp=0;
    for (int i = 1; i <= n; ++i)
    {
        
        if (!x[i].lat)
        {
            csp++;
            mely(i,csp);
        }
        cout << i << " " << csp << "\n";
    }
    for (int i = 1; i <= n; ++i)
    {
        if (!x[i].lat1)
        {
            if (x[i].csop != 1)
                mely3(i);
            else mely2(i);
        }
    }
    if (csp>1)
    {
        cout << "2" << "\n";
    }
    else cout << "1"<<"\n";
        for (auto& e : ans)cout << e << " ";
        if (csp>1)
        {
            for (auto& e : ans2)cout << e << " ";
            cout << "\n";
            for (auto& e : ans2)cout << e << " ";
            for (auto& e : ans)cout << e << " ";
        }
    
    return 0;
}

/* 5 9
3 1
3 5
3 4
4 2
3 2
1 4
1 2
1 5
5 4
*/

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
base3/50
1Wrong answer0/03ms1808 KiB
2Wrong answer0/03ms2008 KiB
3Wrong answer0/0333ms44672 KiB
4Wrong answer0/23ms4704 KiB
5Wrong answer0/33ms5060 KiB
6Wrong answer0/33ms5056 KiB
7Wrong answer0/33ms5012 KiB
8Accepted1/13ms4968 KiB
9Wrong answer0/33ms4968 KiB
10Wrong answer0/34ms5576 KiB
11Wrong answer0/34ms5852 KiB
12Accepted1/14ms5744 KiB
13Wrong answer0/24ms6080 KiB
14Wrong answer0/34ms5728 KiB
15Wrong answer0/1266ms37060 KiB
16Wrong answer0/3248ms46092 KiB
17Wrong answer0/5115ms41004 KiB
18Wrong answer0/1352ms67272 KiB
19Partially correct1/2247ms44784 KiB
20Wrong answer0/3340ms65928 KiB
21Wrong answer0/4342ms73564 KiB
22Wrong answer0/4365ms71508 KiB