52692023-04-25 06:17:37anonDinókcpp17Time limit exceeded 60/100544ms92356 KiB
#include <vector>
#include <queue>
#include <unordered_set>
#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<unordered_set<ll>> g(2 * N + 1);

    for(i = 0; i < M; i++)
    {
        switch(ss[i][0])
        {
            case 1:
                g[ss[i][1]].insert(ss[i][2] + N);
                g[ss[i][2]].insert(ss[i][1] + N);
            break;
            case 2:
                g[ss[i][1] + N].insert(ss[i][2]);
            break;
            default:
            break;
        }
    }

    for(i = 1; i <= N; i++)
        g[i].insert(i + N);

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

    for(i = 1; i <= 2 * N; i++)
    {
        for(auto x : g[i])
            ine[x]++;
    }

    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
1Accepted3ms1684 KiB
2Accepted3ms1928 KiB
3Accepted10ms6248 KiB
subtask20/5
4Time limit exceeded544ms83552 KiB
5Accepted300ms72232 KiB
6Accepted237ms66424 KiB
subtask315/15
7Accepted3ms2908 KiB
8Accepted3ms2972 KiB
9Accepted3ms3216 KiB
10Accepted2ms3328 KiB
11Accepted3ms3328 KiB
12Accepted3ms3448 KiB
subtask410/10
13Accepted3ms3720 KiB
14Accepted3ms3492 KiB
15Accepted3ms3496 KiB
16Accepted3ms3572 KiB
17Accepted3ms3656 KiB
subtask535/35
18Accepted3ms3648 KiB
19Accepted4ms4444 KiB
20Accepted388ms92144 KiB
21Accepted485ms92356 KiB
22Accepted3ms4292 KiB
23Accepted4ms5216 KiB
24Accepted229ms92148 KiB
subtask60/35
25Accepted460ms88116 KiB
26Time limit exceeded544ms88120 KiB
27Accepted402ms88364 KiB
28Accepted490ms88328 KiB
29Accepted286ms90524 KiB
30Accepted433ms89560 KiB
31Accepted483ms88704 KiB
32Accepted233ms90780 KiB
33Accepted215ms92172 KiB
34Accepted370ms89700 KiB
35Accepted239ms87056 KiB