51122023-04-17 22:48:24nmarciDinókcpp11Accepted 100/100171ms76280 KiB
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <deque>
#include <set>

using namespace std;
using ll = long long int;

set<int> g[200100];
int l[100100], r[100100];
int val[200100];
int color[200100];
deque<int> q;
int ido = 0;
bool topsort(int node) {
    color[node] = 1;
    bool ans = true;
    for (auto i : g[node]) {
        if (color[i] == 1) {
            cout << "NEM" << endl;
            exit(0);
            return false;
        }
        else if (color[i] == 0) {
            ans &= topsort(i);
        }
    }
    q.push_front(node);
    color[node] = 2;
    return ans;
}

vector<pair<int, int>> kettes;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    int cnt = 1;
    for (int i = 1; i <= n; ++i) {
        l[i] = cnt++;
        r[i] = cnt++;
        g[l[i]].emplace(r[i]);
    }
    while (m--) {
        int t, a, b;
        cin >> t >> a >> b;
        if (t == 1) {
            g[l[b]].emplace(r[a]);    //ok
            g[l[a]].emplace(r[b]);
        }
        if (t == 2) {
            g[r[a]].emplace(l[b]);
        }
    }
    /*for (int i = 1; i <= 2 * n; ++i) {
        for (auto j : g[i]) {
            cerr << j << " ";
        }
        cerr << endl;
    }*/
        for (int i = 1; i <= 2 * n; ++i) {
            color[i] = 0;
        }
        q.clear();
        
        bool ok = true;
        for (int i = 1; i <= 2 * n; ++i) {
            if (!color[i]) ok &= topsort(i);
        }
        if (ok) {
            for (int i = 0; i < 2 * n; ++i) {
                val[q[i]] = i + 1;
            }
            cout << "IGEN\n";
            for (int i = 1; i <= n; ++i) {
                cout << val[l[i]] << " " << val[r[i]] << "\n";
            }
            return 0;
        }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted8ms20700 KiB
2Accepted10ms20980 KiB
3Accepted14ms22632 KiB
subtask25/5
4Accepted155ms57376 KiB
5Accepted93ms48876 KiB
6Accepted75ms44744 KiB
subtask315/15
7Accepted9ms24560 KiB
8Accepted10ms24644 KiB
9Accepted10ms24608 KiB
10Accepted9ms24876 KiB
11Accepted8ms24952 KiB
12Accepted8ms25320 KiB
subtask410/10
13Accepted8ms25248 KiB
14Accepted8ms25160 KiB
15Accepted8ms25432 KiB
16Accepted8ms25540 KiB
17Accepted8ms25648 KiB
subtask535/35
18Accepted10ms25660 KiB
19Accepted10ms25764 KiB
20Accepted111ms52164 KiB
21Accepted108ms53504 KiB
22Accepted8ms28324 KiB
23Accepted9ms28548 KiB
24Accepted78ms51824 KiB
subtask635/35
25Accepted171ms62764 KiB
26Accepted140ms64152 KiB
27Accepted150ms65384 KiB
28Accepted142ms66840 KiB
29Accepted92ms63420 KiB
30Accepted137ms68932 KiB
31Accepted137ms70808 KiB
32Accepted89ms67480 KiB
33Accepted75ms66064 KiB
34Accepted152ms75448 KiB
35Accepted119ms76280 KiB