52712023-04-25 06:28:37anonDinókcpp17Accepted 100/100402ms43444 KiB
#include <vector>
#include <queue>
#include <iostream>

using ll = long long;
using namespace std;

int main()
{
    ll i, j, c, e, t, a, b, N, M;

    cin >> N >> M;

    vector<vector<ll>> ss(M);

    for(i = 0; i < M; i++)
    {
        cin >> t >> a >> b;
        ss[i] = vector<ll> { t, a, b };
    }

    vector<vector<ll>> g(2 * N + 1);
    vector<ll> ine(2 * N + 1, 0);

    for(i = 1; i <= N; i++)
    {
        g[i].push_back(i + N);
        ine[i + N]++;
    }

    for(i = 0; i < M; i++)
    {
        switch(ss[i][0])
        {
            case 1:
                g[ss[i][1]].push_back(ss[i][2] + N);
                ine[ss[i][2] + N]++;

                g[ss[i][2]].push_back(ss[i][1] + N);
                ine[ss[i][1] + N]++;
            break;
            case 2:
                g[ss[i][1] + N].push_back(ss[i][2]);
                ine[ss[i][2]]++;
            break;
            default:
            break;
        }
    }

    c = 1;
    vector<ll> ans(2 * N + 1, 0);

    queue<ll> q;

    for(i = 1; i <= N; i++)
    {
        if(!ine[i])
            q.push(i);
    }

    while(q.size())
    {
        e = q.front();
        q.pop();

        ans[e] = c++;

        for(auto x : g[e])
        {
            if(!--ine[x])
                q.push(x);
        }
    }

    for(i = 1; i <= 2 * N; i++)
    {
        if(!ans[i])
        {
            cout << "NEM" << endl;
            return 0;
        }
    }

    cout << "IGEN" << endl;

    for(i = 1; i <= N; i++)
        cout << ans[i] << ' ' << ans[i + N] << endl;

    return 0;
}

SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1812 KiB
2Accepted3ms2056 KiB
3Accepted8ms4260 KiB
subtask25/5
4Accepted344ms41336 KiB
5Accepted200ms33700 KiB
6Accepted193ms30156 KiB
subtask315/15
7Accepted3ms2908 KiB
8Accepted3ms3128 KiB
9Accepted3ms3512 KiB
10Accepted2ms3412 KiB
11Accepted2ms3416 KiB
12Accepted3ms3660 KiB
subtask410/10
13Accepted3ms3872 KiB
14Accepted3ms4080 KiB
15Accepted2ms4048 KiB
16Accepted3ms4184 KiB
17Accepted3ms4260 KiB
subtask535/35
18Accepted3ms4276 KiB
19Accepted4ms4536 KiB
20Accepted300ms42008 KiB
21Accepted245ms42140 KiB
22Accepted3ms4352 KiB
23Accepted4ms4776 KiB
24Accepted136ms42504 KiB
subtask635/35
25Accepted272ms42520 KiB
26Accepted273ms42268 KiB
27Accepted308ms42272 KiB
28Accepted287ms42268 KiB
29Accepted141ms41668 KiB
30Accepted264ms42188 KiB
31Accepted402ms42400 KiB
32Accepted150ms41824 KiB
33Accepted136ms41884 KiB
34Accepted257ms42532 KiB
35Accepted137ms43444 KiB