166952025-05-09 11:23:31TaxiradioDinókcpp17Accepted 100/100165ms13108 KiB
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
using namespace std;

int u = 0;
vector<int> t;
vector<vector<int>> g;

void dfs(int h){
    t[h] = -2;
    for(int x : g[h]){
        if(t[x] == -2){
            cout << "NEM" << endl;
            exit(0);
        }
        if(t[x] == -1)dfs(x);
    }
    t[h] = u++;
}

int main() {
	int n , m; cin >> n >> m;
    t.resize(2*n , -1);
    g.resize(2*n);
    for(int i = 0; i < m; i++){
        int a , b , c; cin >> a >> b >> c;b--;c--;
        if(a == 1){
            g[c+n].push_back(b);
            g[b+n].push_back(c);
        }else{
            g[c].push_back(b+n);
        }
    }
    for(int i = 0; i < n; i++)g[i+n].push_back(i);
    for(int i = 0; i < n*2; i++)if(t[i] == -1)dfs(i);
    cout << "IGEN" << endl;
    for(int i = 0; i < n; i++)cout << t[i]+1 << " " << t[i+n]+1 << "\n";
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms316 KiB
2Accepted1ms316 KiB
3Accepted6ms832 KiB
subtask25/5
4Accepted145ms11872 KiB
5Accepted90ms10912 KiB
6Accepted64ms10440 KiB
subtask315/15
7Accepted1ms316 KiB
8Accepted1ms508 KiB
9Accepted1ms316 KiB
10Accepted1ms316 KiB
11Accepted1ms316 KiB
12Accepted1ms316 KiB
subtask410/10
13Accepted1ms316 KiB
14Accepted1ms508 KiB
15Accepted1ms316 KiB
16Accepted1ms316 KiB
17Accepted1ms508 KiB
subtask535/35
18Accepted1ms316 KiB
19Accepted1ms348 KiB
20Accepted159ms13108 KiB
21Accepted149ms13108 KiB
22Accepted1ms316 KiB
23Accepted2ms316 KiB
24Accepted115ms11952 KiB
subtask635/35
25Accepted162ms12348 KiB
26Accepted163ms12340 KiB
27Accepted151ms12340 KiB
28Accepted149ms12340 KiB
29Accepted119ms11572 KiB
30Accepted165ms12592 KiB
31Accepted148ms12344 KiB
32Accepted125ms11436 KiB
33Accepted112ms12192 KiB
34Accepted157ms12340 KiB
35Accepted112ms10532 KiB